Project

General

Profile

Bug #11759 » 11759-rev2.patch

colindkelley (Colin Kelley), 12/05/2015 04:15 PM

View differences:

lib/uri/generic.rb
# frozen_string_literal: true
# = uri/generic.rb
#
# Author:: Akira Yamada <akira@ruby-lang.org>
......
# if properly formatted as 'user:password'
def split_userinfo(ui)
return nil, nil unless ui
user, password = ui.split(':'.freeze, 2)
user, password = ui.split(':', 2)
return user, password
end
......
# If scheme is ftp, path may be relative.
# See RFC 1738 section 3.2.2, and RFC 2396.
if @scheme && @scheme != "ftp".freeze
if v && v != ''.freeze && parser.regexp[:ABS_PATH] !~ v
if @scheme && @scheme != "ftp"
if v && v != '' && parser.regexp[:ABS_PATH] !~ v
raise InvalidComponentError,
"bad component(expected absolute path component): #{v}"
end
else
if v && v != ''.freeze && parser.regexp[:ABS_PATH] !~ v &&
if v && v != '' && parser.regexp[:ABS_PATH] !~ v &&
parser.regexp[:REL_PATH] !~ v
raise InvalidComponentError,
"bad component(expected relative path component): #{v}"
......
x = v.to_str
v = x.dup if x.equal? v
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.gsub!(/(?!%\h\h|[!$-&(-;=?-_a-~])./n.freeze){'%%%02X'.freeze % $&.ord}
v.gsub!(/(?!%\h\h|[!$-&(-;=?-_a-~])./n.freeze){'%%%02X' % $&.ord}
v.force_encoding(Encoding::US_ASCII)
@query = v
end
......
x = v.to_str
v = x.dup if x.equal? v
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.gsub!(/(?!%\h\h|[!-~])./n){'%%%02X'.freeze % $&.ord}
v.gsub!(/(?!%\h\h|[!-~])./n){'%%%02X' % $&.ord}
v.force_encoding(Encoding::US_ASCII)
@fragment = v
end
......
# Constructs String from URI
#
def to_s
str = ''
str = ''.dup
if @scheme
str << @scheme
str << ':'.freeze
str << ':'
end
if @opaque
str << @opaque
else
if @host
str << '//'.freeze
str << '//'
end
if self.userinfo
str << self.userinfo
str << '@'.freeze
str << '@'
end
if @host
str << @host
end
if @port && @port != self.default_port
str << ':'.freeze
str << ':'
str << @port.to_s
end
str << @path
if @query
str << '?'.freeze
str << '?'
str << @query
end
end
if @fragment
str << '#'.freeze
str << '#'
str << @fragment
end
str
(3-3/4)