diff options
Diffstat (limited to 'lib/uri/generic.rb')
-rw-r--r-- | lib/uri/generic.rb | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index bacd90382d..5c134e5924 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -543,7 +543,7 @@ module URI # if properly formatted as 'user:password' def split_userinfo(ui) return nil, nil unless ui - user, password = ui.split(/:/, 2) + user, password = ui.split(':'.freeze, 2) return user, password end @@ -695,13 +695,7 @@ module URI # see also URI::Generic.port= # def set_port(v) - unless !v || v.kind_of?(Fixnum) - if v.empty? - v = nil - else - v = v.to_i - end - end + v = v.empty? ? nil : v.to_i unless !v || v.kind_of?(Fixnum) @port = v end protected :set_port @@ -768,13 +762,14 @@ module URI # If scheme is ftp, path may be relative. # See RFC 1738 section 3.2.2, and RFC 2396. - if @scheme && @scheme != "ftp" - if v && v != '' && parser.regexp[:ABS_PATH] !~ v + if @scheme && @scheme != "ftp".freeze + if v && v != ''.freeze && parser.regexp[:ABS_PATH] !~ v raise InvalidComponentError, "bad component(expected absolute path component): #{v}" end else - if v && v != '' && parser.regexp[:ABS_PATH] !~ v && parser.regexp[:REL_PATH] !~ v + if v && v != ''.freeze && parser.regexp[:ABS_PATH] !~ v && + parser.regexp[:REL_PATH] !~ v raise InvalidComponentError, "bad component(expected relative path component): #{v}" end @@ -849,7 +844,7 @@ module URI x = v.to_str v = x.dup if x.equal? v v.encode!(Encoding::UTF_8) rescue nil - v.delete!("\t\r\n") + v.delete!("\t\r\n".freeze) v.force_encoding(Encoding::ASCII_8BIT) v.gsub!(/(?!%\h\h|[!$-&(-;=?-_a-~])./n.freeze){'%%%02X'.freeze % $&.ord} v.force_encoding(Encoding::US_ASCII) @@ -939,9 +934,9 @@ module URI x = v.to_str v = x.dup if x.equal? v v.encode!(Encoding::UTF_8) rescue nil - v.delete!("\t\r\n") + v.delete!("\t\r\n".freeze) v.force_encoding(Encoding::ASCII_8BIT) - v.gsub!(/(?!%\h\h|[!-~])./n){'%%%02X' % $&.ord} + v.gsub!(/(?!%\h\h|[!-~])./n){'%%%02X'.freeze % $&.ord} v.force_encoding(Encoding::US_ASCII) @fragment = v end |