* lib/uri/generic.rb (URI::Generic.build): duplicate args before adding
new items. (don't change arguments) * lib/uri/generic.rb (URI::Generic.build): use URI::Generic::COMPONENT if this method is called from URI::Generic. * lib/uri/generic.rb (URI::Generic.build2): escape only if the item is a String. * lib/uri/generic.rb (URI::Generic.build2): use DEFAULT_PARSER because it doesn't have parser method. [Bug #6420] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35692 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
69305da74d
commit
9381cd1184
14
ChangeLog
14
ChangeLog
@ -1,3 +1,17 @@
|
|||||||
|
Fri May 18 15:20:56 2012 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/uri/generic.rb (URI::Generic.build): duplicate args before adding
|
||||||
|
new items. (don't change arguments)
|
||||||
|
|
||||||
|
* lib/uri/generic.rb (URI::Generic.build): use URI::Generic::COMPONENT
|
||||||
|
if this method is called from URI::Generic.
|
||||||
|
|
||||||
|
* lib/uri/generic.rb (URI::Generic.build2): escape only if the item is
|
||||||
|
a String.
|
||||||
|
|
||||||
|
* lib/uri/generic.rb (URI::Generic.build2): use DEFAULT_PARSER because
|
||||||
|
it doesn't have parser method. [Bug #6420]
|
||||||
|
|
||||||
Fri May 18 15:54:07 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
Fri May 18 15:54:07 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
* ext/zlib/extconf.rb: Use an exception instaed of bare puts.
|
* ext/zlib/extconf.rb: Use an exception instaed of bare puts.
|
||||||
|
@ -86,8 +86,8 @@ module URI
|
|||||||
rescue InvalidComponentError
|
rescue InvalidComponentError
|
||||||
if args.kind_of?(Array)
|
if args.kind_of?(Array)
|
||||||
return self.build(args.collect{|x|
|
return self.build(args.collect{|x|
|
||||||
if x
|
if x.is_a?(String)
|
||||||
parser.escape(x)
|
DEFAULT_PARSER.escape(x)
|
||||||
else
|
else
|
||||||
x
|
x
|
||||||
end
|
end
|
||||||
@ -96,7 +96,7 @@ module URI
|
|||||||
tmp = {}
|
tmp = {}
|
||||||
args.each do |key, value|
|
args.each do |key, value|
|
||||||
tmp[key] = if value
|
tmp[key] = if value
|
||||||
parser.escape(value)
|
DEFAULT_PARSER.escape(value)
|
||||||
else
|
else
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
@ -121,7 +121,7 @@ module URI
|
|||||||
def self.build(args)
|
def self.build(args)
|
||||||
if args.kind_of?(Array) &&
|
if args.kind_of?(Array) &&
|
||||||
args.size == ::URI::Generic::COMPONENT.size
|
args.size == ::URI::Generic::COMPONENT.size
|
||||||
tmp = args
|
tmp = args.dup
|
||||||
elsif args.kind_of?(Hash)
|
elsif args.kind_of?(Hash)
|
||||||
tmp = ::URI::Generic::COMPONENT.collect do |c|
|
tmp = ::URI::Generic::COMPONENT.collect do |c|
|
||||||
if args.include?(c)
|
if args.include?(c)
|
||||||
@ -131,8 +131,9 @@ module URI
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
component = self.class.component rescue ::URI::Generic::COMPONENT
|
||||||
raise ArgumentError,
|
raise ArgumentError,
|
||||||
"expected Array of or Hash of components of #{self.class} (#{self.class.component.join(', ')})"
|
"expected Array of or Hash of components of #{self.class} (#{component.join(', ')})"
|
||||||
end
|
end
|
||||||
|
|
||||||
tmp << nil
|
tmp << nil
|
||||||
|
@ -723,4 +723,13 @@ class URI::TestGeneric < Test::Unit::TestCase
|
|||||||
u.hostname = "::1"
|
u.hostname = "::1"
|
||||||
assert_equal("http://[::1]/bar", u.to_s)
|
assert_equal("http://[::1]/bar", u.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_build
|
||||||
|
URI::Generic.build(['http', nil, 'example.com', 80, nil, '/foo', nil, nil, nil])
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_build2
|
||||||
|
URI::Generic.build2(path: "/foo bar/baz")
|
||||||
|
URI::Generic.build2(['http', nil, 'example.com', 80, nil, '/foo bar' , nil, nil, nil])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user