summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--lib/uri/generic.rb11
-rw-r--r--test/uri/test_generic.rb9
3 files changed, 29 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 14bd67fdb6..110aaddf88 100644
--- a/ChangeLog
+++ b/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>
* ext/zlib/extconf.rb: Use an exception instaed of bare puts.
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index 2c453dc9db..0435fd25ce 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -86,8 +86,8 @@ module URI
rescue InvalidComponentError
if args.kind_of?(Array)
return self.build(args.collect{|x|
- if x
- parser.escape(x)
+ if x.is_a?(String)
+ DEFAULT_PARSER.escape(x)
else
x
end
@@ -96,7 +96,7 @@ module URI
tmp = {}
args.each do |key, value|
tmp[key] = if value
- parser.escape(value)
+ DEFAULT_PARSER.escape(value)
else
value
end
@@ -121,7 +121,7 @@ module URI
def self.build(args)
if args.kind_of?(Array) &&
args.size == ::URI::Generic::COMPONENT.size
- tmp = args
+ tmp = args.dup
elsif args.kind_of?(Hash)
tmp = ::URI::Generic::COMPONENT.collect do |c|
if args.include?(c)
@@ -131,8 +131,9 @@ module URI
end
end
else
+ component = self.class.component rescue ::URI::Generic::COMPONENT
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
tmp << nil
diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb
index e0ab049122..6df7bf0069 100644
--- a/test/uri/test_generic.rb
+++ b/test/uri/test_generic.rb
@@ -723,4 +723,13 @@ class URI::TestGeneric < Test::Unit::TestCase
u.hostname = "::1"
assert_equal("http://[::1]/bar", u.to_s)
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