Bug #6057
closed
URI - Nonsensical Behavior
Added by sgonyea (Scott Gonyea) over 12 years ago.
Updated about 6 years ago.
Description
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.
Files
Edit: Moronic comment redacted.
I'd be happy to write this improved functionality. But would it be welcome?
Another example:
URI.join("http://foo.com/baz", "bar", "bim")
Also, if we did model the behavior of Pathname, then joining of "/baz" would reset the path which I do think is acceptable and good behavior.
In my opinion, URI should model the behavior of Pathname.
I totally agree.
Additionally I absolutely dislike using global methods instead of class
factory methods. I think it isn't at all obvious and it poisons the
global namespace.
URI.parse(args) over Kernel#URI(args)
Changing the behavior of URI#+ from the current will break many libraries (including mechanize) that depend upon the current behavior of relative resolution.
The current behavior is frequently used to combine, for example, an anchor href with the current location to generate a new, correct URI if the href is a relative URI like "foo" or "../foo", a complete path like "/foo" or a complete URI like "http://other.example/bar".
Scott Gonyea scott@aitrus.org writes:
Issue #6057 has been updated by Scott Gonyea.
I'd be happy to write this improved functionality. But would it be welcome?
Is there anyone who actually likes this behavior?
- Assignee set to akira (akira yamada)
- Status changed from Open to Assigned
- Description updated (diff)
- Has duplicate Bug #10075: URI#join needs documentation of its behavior added
- Related to Bug #15276: URI.join behaviour is unintuitive added
- Status changed from Assigned to Closed
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0