mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
d918f9f34f
commit
f2b75020ba
3 changed files with 54 additions and 19 deletions
|
@ -1,3 +1,12 @@
|
|||
Wed Jun 9 16:09:01 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 15:39:55 2004 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* configure.in: Add support for DragonFly BSD.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue