summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--lib/uri/generic.rb50
-rw-r--r--test/uri/test_generic.rb14
3 files changed, 54 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 3913bc5c01..f77ba8d1d3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Wed Jun 9 18:04:14 2004 akira yamada <akira@ruby-lang.org>
+
+ * 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.
+
Wed Jun 9 17:39:37 2004 Akinori MUSHA <knu@iDaemons.org>
* config.guess, config.sub: Update to a more recent version as of
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)
diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb
index 25d01f0606..770a6f6151 100644
--- a/test/uri/test_generic.rb
+++ b/test/uri/test_generic.rb
@@ -158,6 +158,11 @@ class TestGeneric < Test::Unit::TestCase
assert_equal('http://foo/bar/', u.to_s)
assert(nil != u.merge!("../baz"))
assert_equal('http://foo/baz', u.to_s)
+
+ # [ruby-dev:23628]
+ u0 = URI.parse('mailto:foo@example.com')
+ u1 = URI.parse('mailto:foo@example.com#bar')
+ assert_equal(uri_to_ary(u0 + '#bar'), uri_to_ary(u1))
end
def test_route
@@ -180,6 +185,15 @@ class TestGeneric < Test::Unit::TestCase
url = URI.parse('file:///a/b/').route_to('file:///a/b/')
assert_equal('', url.to_s)
+
+ url = URI.parse('mailto:foo@example.com').route_to('mailto:foo@example.com#bar')
+ assert_equal('#bar', url.to_s)
+
+ url = URI.parse('mailto:foo@example.com#bar').route_to('mailto:foo@example.com')
+ assert_equal('', url.to_s)
+
+ url = URI.parse('mailto:foo@example.com').route_to('mailto:foo@example.com')
+ assert_equal('', url.to_s)
end
def test_rfc2396_examples