From fa1261e0938e3a8aa92f49b290fcfa7e8a4cddda Mon Sep 17 00:00:00 2001 From: akira Date: Wed, 9 Jun 2004 09:05:41 +0000 Subject: * lib/uri/generic.rb (URI::Generic::merge, URI::Generic::route_from): accepts non-hierarchical URI. [ruby-dev:23631] * test/uri/test_generic.rb (TestGeneric::test_route, TestGeneric::test_merge): added tests for above changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/uri/generic.rb | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) (limited to 'lib/uri') diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index aebb924e85..3d6cc8525b 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -726,7 +726,12 @@ module URI # # => # # def merge(oth) - base, rel = merge0(oth) + begin + base, rel = merge0(oth) + rescue + raise $!.class, $!.message + end + if base == rel return base end @@ -734,7 +739,7 @@ module URI authority = rel.userinfo || rel.host || rel.port # RFC2396, Section 5.2, 2) - if rel.path.empty? && !authority && !rel.query + if (rel.path.nil? || rel.path.empty?) && !authority && !rel.query base.set_fragment(rel.fragment) if rel.fragment return base end @@ -744,10 +749,10 @@ module URI # RFC2396, Section 5.2, 4) if !authority - base.set_path(merge_path(base.path, rel.path)) + base.set_path(merge_path(base.path, rel.path)) if base.path && rel.path else # RFC2396, Section 5.2, 4) - base.set_path(rel.path) + base.set_path(rel.path) if rel.path end # RFC2396, Section 5.2, 7) @@ -785,14 +790,6 @@ module URI return oth, oth end - if !self.hierarchical? - raise BadURIError, - "not hierarchical URI: #{self}" - elsif !oth.hierarchical? - raise BadURIError, - "not hierarchical URI: #{oth}" - end - if self.absolute? return self.dup, oth else @@ -861,12 +858,8 @@ module URI "relative URI: #{oth}" end - if !self.hierarchical? || !oth.hierarchical? - return self, self.dup - end - if self.scheme != oth.scheme - return oth, oth.dup + return self, self.dup end rel = URI::Generic.new(nil, # it is relative URI self.userinfo, self.host, self.port, @@ -876,6 +869,9 @@ module URI if rel.userinfo != oth.userinfo || rel.host.to_s.downcase != oth.host.to_s.downcase || rel.port != oth.port + if self.userinfo.nil? && self.host.nil? + return self, self.dup + end rel.set_port(nil) if rel.port == oth.default_port return rel, rel end @@ -883,10 +879,14 @@ module URI rel.set_host(nil) rel.set_port(nil) - if rel.path == oth.path + if rel.path && rel.path == oth.path rel.set_path('') rel.set_query(nil) if rel.query == oth.query return rel, rel + elsif rel.opaque && rel.opaque == oth.opaque + rel.set_opaque('') + rel.set_query(nil) if rel.query == oth.query + return rel, rel end # you can modify `rel', but can not `oth'. @@ -913,7 +913,11 @@ module URI # def route_from(oth) # you can modify `rel', but can not `oth'. - oth, rel = route_from0(oth) + begin + oth, rel = route_from0(oth) + rescue + raise $!.class, $!.message + end if oth == rel return rel end @@ -1045,6 +1049,14 @@ module URI end end + def hash + self.component_ary.hash + end + + def eql?(oth) + self.component_ary.eql?(oth.component_ary) + end + =begin --- URI::Generic#===(oth) -- cgit v1.2.3