summaryrefslogtreecommitdiff
path: root/lib/uri
diff options
context:
space:
mode:
authorakira <akira@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-06-09 07:15:56 +0000
committerakira <akira@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-06-09 07:15:56 +0000
commitf2b75020ba193b6d20788c800fde583ca8e900d5 (patch)
tree08038054c9623a1e0350b82e0a9e0b2fd50af5eb /lib/uri
parentd918f9f34fd189cb0adc947a16792389104de623 (diff)
* 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/trunk@6437 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/uri')
-rw-r--r--lib/uri/generic.rb50
1 files changed, 31 insertions, 19 deletions
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
# # => #<URI::HTTP:0x2021f3b0 URL:http://my.rubysite.com/main.rbx?page=1>
#
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)