[ruby-core:64081] [ruby-trunk - Bug #10075] [Closed] URI#join needs documentation of its behavior

From: e@...
Date: 2014-07-27 20:34:33 UTC
List: ruby-core #64081
Issue #10075 has been updated by Zachary Scott.

Status changed from Assigned to Closed
% Done changed from 0 to 100

Applied in changeset r46979.

----------
* lib/uri/common.rb: [DOC] [Bug #10075] Clarify how URI.join arguments
  are handled by RFC3986, originall reported by John Feminella.

----------------------------------------
Bug #10075: URI#join needs documentation of its behavior
https://bugs.ruby-lang.org/issues/10075#change-48090

* Author: John Feminella
* Status: Closed
* Priority: Normal
* Assignee: Zachary Scott
* Category: doc
* Target version: current: 2.2.0
* ruby -v: ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
The [documentation](http://www.ruby-doc.org/stdlib-2.1.2/libdoc/uri/rdoc/URI.html#method-c-join) for `URI.join` says:

> "Joins URIs."

Let's look at what a similar `join` method [documentation](http://www.ruby-doc.org/core-2.1.2/File.html#method-c-join) says, on `File`:

> Returns a new string formed by joining the strings using File::SEPARATOR.

That seems pretty clear. Indeed, we get:

~~~
File.join 'path', 'to', 'join'
# => "path/to/join"
~~~

which is what we expected. What do we get if we try the natural `URI` equivalent?

~~~
> URI.join('http://example.com', 'foo', 'bar')
~~~

We probably expect something like:

~~~
# => "http://example.com/foo/bar"
~~~

but we'll actually get

~~~
# => "http://example.com/bar"
~~~

This seems surprising and counterintuitive, even if it matches the documentation behavior, because the documentation doesn't explain why that's the case. I think if Ruby is going to be surprising in that way, it needs to explain that to users in the documentation.



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

In This Thread

Prev Next