This project is closed and read-only.
Backport #3506 closed
Kernel::URI with optional parser
Added by marcandre (Marc-Andre Lafortune) over 16 years ago.
Updated over 14 years ago.
Description
=begin
Kernel::URI could accept an optional parameter to specify a parser.
It could then be used in a couple of places in the library itself.
Patch follows:
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index bda6718..f9f0a6a 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -185,14 +185,7 @@ module URI
end
uris[0] = self.parse(uris[0])
"bad argument(expected URI object or URI string)"
uris[0] = URI(uris[0], self)
uris.inject :merge
end
@@ -845,12 +838,12 @@ module Kernel
#
# Returns +uri+ converted to a URI object.
#
def URI(uri, parser = URI::DEFAULT_PARSER)
case uri
when URI::Generic
uri
when String
else
raise ArgumentError,
"bad argument (expected URI object or URI string)"
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index 4fdfd14..4084b56 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -783,14 +783,7 @@ module URI
return base and rel.¶
you can modify base', but can not rel'.¶
def merge0(oth)
"bad argument(expected URI object or URI string)"
oth = URI(oth, parser)
if self.relative? && oth.relative?
raise BadURIError,
@@ -854,15 +847,7 @@ module URI
private :route_from_path
"bad argument(expected URI object or URI string)"
oth = URI(oth, parser)
if self.relative?
raise BadURIError,
"relative URI: #{self}"
@@ -966,16 +951,7 @@ module URI
# #=> #<URI::Generic:0x2020c2f6 URL:/main.rbx?page=1>
#
def route_to(oth)
"bad argument(expected URI object or URI string)"
URI(oth, parser).route_from(self)
end
=end
Priority changed from 3 to Normal
=begin
Moving this to "Bug", after Yui Naruse's remark in [ruby-core:30964] that objects with a to_str method should be acceptable. That's not currently the case:
rubydev -r uri -e 'class X;def to_s;"foo" end end; URI.join("/a", X.new)'
/usr/local/rubydev/lib/ruby/1.9.1/uri/generic.rb:746:in `rescue in merge': bad argument(expected URI object or URI string) (ArgumentError)
We could have a URI.try_convert method too...
=end
Assignee changed from akira (akira yamada) to marcandre (Marc-Andre Lafortune)
ruby -v set to r28670
Category set to lib
Assignee changed from marcandre (Marc-Andre Lafortune) to yugui (Yuki Sonoda)
=begin
Fixed in trunk with r28699.
Yugui/Yusuke: Let me know if you'd like me to backport it to 1.9.2
=end
Status changed from Open to Assigned
Description updated (diff )
Status changed from Assigned to Closed
Also available in: PDF
Atom