aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--lib/uri/common.rb29
2 files changed, 25 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 4febe46b40..9db369ef1b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Jul 21 12:31:30 2010 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
+
+ * lib/uri/common.rb: Have URI() and URI.join accept URI objects in
+ addition to strings. [ruby-core:30960]
+
Wed Jul 21 11:55:06 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* util.c (ruby_hdtoa): renamed from BSD__hdtoa.
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index 58fd422a5d..a41cd678d9 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -184,12 +184,15 @@ module URI
end
end
- def join(*str)
- u = self.parse(str[0])
- str[1 .. -1].each do |x|
- u = u.merge(x)
+ def join(*uris)
+ if uris[0].is_a?(URI::Generic)
+ elsif uri = String.try_convert(uris[0])
+ uris[0] = self.parse(uri)
+ else
+ raise ArgumentError,
+ "bad argument(expected URI object or URI string)"
end
- u
+ uris.inject :merge
end
def extract(str, schemes = nil, &block)
@@ -837,11 +840,19 @@ module URI
end
module Kernel
- # alias for URI.parse.
+
#
- # This method is introduced at 1.8.2.
- def URI(uri_str) # :doc:
- URI.parse(uri_str)
+ # Returns +uri+ converted to a URI object.
+ #
+ def URI(uri)
+ if uri.is_a?(URI::Generic)
+ uri
+ elsif uri = String.try_convert(uri)
+ URI.parse(uri)
+ else
+ raise ArgumentError,
+ "bad argument (expected URI object or URI string)"
+ end
end
module_function :URI
end