diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index fce8a8a..14b10fc 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -1226,7 +1226,7 @@ def route_from0(oth) "relative URI: #{oth}" end - if self.scheme != oth.scheme + if self.scheme != oth.scheme || self.hierarchical? != oth.hierarchical? return self, self.dup end rel = URI::Generic.new(nil, # it is relative URI diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb index 9006125..1ec7763 100644 --- a/test/uri/test_generic.rb +++ b/test/uri/test_generic.rb @@ -368,6 +368,18 @@ def test_route url = URI.parse('mailto:foo@example.com').route_to('mailto:foo@example.com') assert_equal('', url.to_s) + + url = URI.parse('file:notes.txt').route_to('file:/home/alice/notes.txt') + assert_equal('file:///home/alice/notes.txt', url.to_s) + + url = URI.parse('file:/home/alice/notes.txt').route_to('file:notes.txt') + assert_equal('file:notes.txt', url.to_s) + + url = URI.parse('file:notes.txt').route_to('file:/home/alice/../bob/notes.txt') + assert_equal('file:///home/alice/../bob/notes.txt', url.to_s) + + url = URI.parse('http:example.com').route_to('http://example.com/about') + assert_equal('http://example.com/about', url.to_s) end def test_rfc3986_examples