lib/uri/generic.rb: enable frozen_string_literal

* lib/uri/generic.rb: enable frozen_string_literal
  (split_userinfo): remove explicit .freeze for string literals
  (check_path): ditto
  (query): ditto
  (fragment): ditto
  (to_s): ditto
  [ruby-core:71910] [Bug #11759]

Patch-by: Colin Kelley <colindkelley@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2015-12-08 21:28:26 +00:00
parent 0df938d5be
commit f2b9563bb4
2 changed files with 27 additions and 15 deletions

View File

@ -1,3 +1,13 @@
Wed Dec 9 06:26:23 2015 Colin Kelley <colindkelley@gmail.com>
* lib/uri/generic.rb: enable frozen_string_literal
(split_userinfo): remove explicit .freeze for string literals
(check_path): ditto
(query): ditto
(fragment): ditto
(to_s): ditto
[ruby-core:71910] [Bug #11759]
Wed Dec 9 06:25:47 2015 Eric Wong <e@80x24.org> Wed Dec 9 06:25:47 2015 Eric Wong <e@80x24.org>
* test/uri/test_generic.rb (to_s): new test * test/uri/test_generic.rb (to_s): new test

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# = uri/generic.rb # = uri/generic.rb
# #
# Author:: Akira Yamada <akira@ruby-lang.org> # Author:: Akira Yamada <akira@ruby-lang.org>
@ -543,7 +545,7 @@ module URI
# if properly formatted as 'user:password' # if properly formatted as 'user:password'
def split_userinfo(ui) def split_userinfo(ui)
return nil, nil unless ui return nil, nil unless ui
user, password = ui.split(':'.freeze, 2) user, password = ui.split(':', 2)
return user, password return user, password
end end
@ -762,13 +764,13 @@ module URI
# If scheme is ftp, path may be relative. # If scheme is ftp, path may be relative.
# See RFC 1738 section 3.2.2, and RFC 2396. # See RFC 1738 section 3.2.2, and RFC 2396.
if @scheme && @scheme != "ftp".freeze if @scheme && @scheme != "ftp"
if v && v != ''.freeze && parser.regexp[:ABS_PATH] !~ v if v && v != '' && parser.regexp[:ABS_PATH] !~ v
raise InvalidComponentError, raise InvalidComponentError,
"bad component(expected absolute path component): #{v}" "bad component(expected absolute path component): #{v}"
end end
else else
if v && v != ''.freeze && parser.regexp[:ABS_PATH] !~ v && if v && v != '' && parser.regexp[:ABS_PATH] !~ v &&
parser.regexp[:REL_PATH] !~ v parser.regexp[:REL_PATH] !~ v
raise InvalidComponentError, raise InvalidComponentError,
"bad component(expected relative path component): #{v}" "bad component(expected relative path component): #{v}"
@ -844,9 +846,9 @@ module URI
x = v.to_str x = v.to_str
v = x.dup if x.equal? v v = x.dup if x.equal? v
v.encode!(Encoding::UTF_8) rescue nil v.encode!(Encoding::UTF_8) rescue nil
v.delete!("\t\r\n".freeze) v.delete!("\t\r\n")
v.force_encoding(Encoding::ASCII_8BIT) v.force_encoding(Encoding::ASCII_8BIT)
v.gsub!(/(?!%\h\h|[!$-&(-;=?-_a-~])./n.freeze){'%%%02X'.freeze % $&.ord} v.gsub!(/(?!%\h\h|[!$-&(-;=?-_a-~])./n.freeze){'%%%02X' % $&.ord}
v.force_encoding(Encoding::US_ASCII) v.force_encoding(Encoding::US_ASCII)
@query = v @query = v
end end
@ -934,9 +936,9 @@ module URI
x = v.to_str x = v.to_str
v = x.dup if x.equal? v v = x.dup if x.equal? v
v.encode!(Encoding::UTF_8) rescue nil v.encode!(Encoding::UTF_8) rescue nil
v.delete!("\t\r\n".freeze) v.delete!("\t\r\n")
v.force_encoding(Encoding::ASCII_8BIT) v.force_encoding(Encoding::ASCII_8BIT)
v.gsub!(/(?!%\h\h|[!-~])./n){'%%%02X'.freeze % $&.ord} v.gsub!(/(?!%\h\h|[!-~])./n){'%%%02X' % $&.ord}
v.force_encoding(Encoding::US_ASCII) v.force_encoding(Encoding::US_ASCII)
@fragment = v @fragment = v
end end
@ -1339,37 +1341,37 @@ module URI
# Constructs String from URI # Constructs String from URI
# #
def to_s def to_s
str = '' str = String.new
if @scheme if @scheme
str << @scheme str << @scheme
str << ':'.freeze str << ':'
end end
if @opaque if @opaque
str << @opaque str << @opaque
else else
if @host if @host
str << '//'.freeze str << '//'
end end
if self.userinfo if self.userinfo
str << self.userinfo str << self.userinfo
str << '@'.freeze str << '@'
end end
if @host if @host
str << @host str << @host
end end
if @port && @port != self.default_port if @port && @port != self.default_port
str << ':'.freeze str << ':'
str << @port.to_s str << @port.to_s
end end
str << @path str << @path
if @query if @query
str << '?'.freeze str << '?'
str << @query str << @query
end end
end end
if @fragment if @fragment
str << '#'.freeze str << '#'
str << @fragment str << @fragment
end end
str str