Issue #6057 has been updated by Scott Gonyea.


Ah. That's the issue.

1.9.3-p125 :016 > uri = URI("http://google.com/foo/bar/")
 => #<URI::HTTP:0x007fd97a891038 URL:http://google.com/foo/bar/> 
1.9.3-p125 :017 > uri + "baz"
 => #<URI::HTTP:0x007fd97a887ab0 URL:http://google.com/foo/bar/baz> 

If the URI's path itself has a trailing "/" then it will append the new path.

Likewise:

1.9.3-p125 :023 > URI.join("http://google.com/foo/", "bar", "baz")
 => #<URI::HTTP:0x007fd97b8c7308 URL:http://google.com/foo/baz> 
1.9.3-p125 :024 > URI.join("http://google.com/foo/", "bar/", "baz")
 => #<URI::HTTP:0x007fd97b8ba928 URL:http://google.com/foo/bar/baz> 
1.9.3-p125 :025 > 

How very unintuitive :(. I guess the next question would be if `URI.join` actually needs to follow the merge rules to the letter, but I imagine that argument is moot :).

----------------------------------------
Bug #6057: URI - Nonsensical Behavior
https://bugs.ruby-lang.org/issues/6057

Author: Scott Gonyea
Status: Open
Priority: Normal
Assignee: 
Category: lib
Target version: 
ruby -v: 1.9.3-p125


The behavior of Ruby's URI is confusing, to say the least.

URI("http://foo.com/bar") + "baz"
# => #<URI::HTTP:0x710713de URL:http://foo.com/baz> 

URI.join("http://foo.com/baz", "bar")
# => #<URI::HTTP:0x29fd5dc4 URL:http://foo.com/bar>

I could at least understand this behavior being the case if we were adding "/bar" (although it'd still be non-intuitive). That URI throws away its current path makes it a tedious library. Net::HTTP expects it as an input, yet as you interact with URI, you are constantly massaging it into and out of string form.

In my opinion, URI should model the behavior of Pathname.



-- 
http://bugs.ruby-lang.org/