URI.join broken?

Hi,

I have been looking at the documentation and the source of URI.join and
can’t see what I have misunderstood.

http://ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI.html#M009245

I except URI.join(“test.de Archiv | Stiftung Warentest”, “test2”) in an URI which looks
like test.de Archiv | Stiftung Warentest and not like test.de Archiv | Stiftung Warentest. And
from reading the documentation I even expect that
URI.join(“http://test.de/”, “test1”, “test2”) results in
test.de Archiv | Stiftung Warentest and not test.de Archiv | Stiftung Warentest

So, that do I misunderstand about the URI class? :slight_smile: I am using Ruby
1.8.4 from Darwinports on Mac OS X.

Best regards,
Oliver

On 09/04/06, Oliver A. [email protected] wrote:

I except URI.join(“test.de Archiv | Stiftung Warentest”, “test2”) in an URI which looks
like test.de Archiv | Stiftung Warentest and not like test.de Archiv | Stiftung Warentest. And
from reading the documentation I even expect that
URI.join(“http://test.de/”, “test1”, “test2”) results in
test.de Archiv | Stiftung Warentest and not test.de Archiv | Stiftung Warentest

That’s a strange result. It works as expected for me, also using 1.8.4
via Darwin Ports on OS X:

URI.join(“test.de Archiv | Stiftung Warentest”, “test2”).to_s #=>
test.de Archiv | Stiftung Warentest

I don’t think you’re missing anything: you are getting anomalous
output. Are you testing it with the same input data?

Paul.

Paul B. wrote:

On 09/04/06, Oliver A. [email protected] wrote:

I except URI.join(“test.de Archiv | Stiftung Warentest”, “test2”) in an URI which looks
like test.de Archiv | Stiftung Warentest and not like test.de Archiv | Stiftung Warentest. And
from reading the documentation I even expect that
URI.join(“http://test.de/”, “test1”, “test2”) results in
test.de Archiv | Stiftung Warentest and not test.de Archiv | Stiftung Warentest

That’s a strange result. It works as expected for me, also using 1.8.4
via Darwin Ports on OS X:

URI.join(“test.de Archiv | Stiftung Warentest”, “test2”).to_s #=>
test.de Archiv | Stiftung Warentest

Can you explain to me why this is correct? I would expect
test.de Archiv | Stiftung Warentest as the result of your call.

Oliver

On Apr 9, 2006, at 6:22 PM, Oliver A. wrote:

Can you explain to me why this is correct? I would expect
test.de Archiv | Stiftung Warentest as the result of your call.

Oliver

Consider a web browser:

If you are at the site

http://example.com/a

and you click a link whose href is b, its relative and you go to
http://example.com/b

If however the webs server lets you browse directories
and you are at http://example.com/dir/ and you click a link a, you’ll
end up at

http://example.com/dir/a

URL/URIs aren’t quite the same as file paths

Can you explain to me why this is correct? I would expect
test.de Archiv | Stiftung Warentest as the result of your call.

Sorry, I misread your original statement, which might make my reply
confusing.

You are getting the correct results, as others have said.

It works just like in a browser:
http://example.com/one + two => http://example.com/two
http://example.com/one/ + two => http://example.com/one/two
http://example.com/one + /two => http://example.com/two
http://example.com/one/ + /two => http://example.com/two

Paul.

On Apr 10, 2006, at 12:22 AM, Oliver A. wrote:

Paul B. wrote:

URI.join(“test.de Archiv | Stiftung Warentest”, “test2”).to_s #=>
test.de Archiv | Stiftung Warentest

Can you explain to me why this is correct? I would expect
test.de Archiv | Stiftung Warentest as the result of your call.

Think of it this way –

You are in your web-browser on test.de Archiv | Stiftung Warentest. There is a link
to “test2”:

<a href="test2">test2</a>

Would you expect it to go to test.de Archiv | Stiftung Warentest? No, it would
go to test.de Archiv | Stiftung Warentest.

You want:

URI.join(“test.de Archiv | Stiftung Warentest”, “test2”)
^
URI.join(“http://test.de/”, “test1/”, “test2”)
^

– Daniel

Paul B. wrote:

Can you explain to me why this is correct? I would expect
test.de Archiv | Stiftung Warentest as the result of your call.

Sorry, I misread your original statement, which might make my reply
confusing.

You are getting the correct results, as others have said.

It works just like in a browser:
http://example.com/one + two => http://example.com/two
http://example.com/one/ + two => http://example.com/one/two
http://example.com/one + /two => http://example.com/two
http://example.com/one/ + /two => http://example.com/two

Thanks Guys,

now I know at least the logic behind URI.join. I am not sure, if it is
the method of choice for my problem, but I have to think about it and
may be I come back with another question.

Oliver