Forum: Ruby URI.join broken?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
92324d1a212698587be6a5f349c7a9b4?d=identicon&s=25 Oliver Andrich (oandrich)
on 2006-04-09 21:09
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...

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

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

Best regards,
Oliver
2abf5beb51d5d66211d525a72c5cb39d?d=identicon&s=25 Paul Battley (Guest)
on 2006-04-09 22:48
(Received via mailing list)
On 09/04/06, Oliver Andrich <oliver.andrich@gmail.com> wrote:
> I except URI.join("http://test.de/test1", "test2") in an URI which looks
> like http://test.de/test1/test2 and not like http://test.de/test2. And
> from reading the documentation I even expect that
> URI.join("http://test.de/", "test1", "test2") results in
> http://test.de/test1/test2 and not http://test.de/test2

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

URI.join("http://test.de/test1", "test2").to_s #=>
"http://test.de/test2"

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

Paul.
92324d1a212698587be6a5f349c7a9b4?d=identicon&s=25 Oliver Andrich (oandrich)
on 2006-04-10 00:22
Paul Battley wrote:
> On 09/04/06, Oliver Andrich <oliver.andrich@gmail.com> wrote:
>> I except URI.join("http://test.de/test1", "test2") in an URI which looks
>> like http://test.de/test1/test2 and not like http://test.de/test2. And
>> from reading the documentation I even expect that
>> URI.join("http://test.de/", "test1", "test2") results in
>> http://test.de/test1/test2 and not http://test.de/test2
>
> That's a strange result. It works as expected for me, also using 1.8.4
> via Darwin Ports on OS X:
>
> URI.join("http://test.de/test1", "test2").to_s #=>
> "http://test.de/test2"

Can you explain to me why this is correct? I would expect
http://test.de/test1/test2 as the result of your call.

Oliver
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-04-10 00:56
(Received via mailing list)
On Apr 9, 2006, at 6:22 PM, Oliver Andrich wrote:

>
> Can you explain to me why this is correct? I would expect
> http://test.de/test1/test2 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
9358cc96c46055cd68d4a76a9aefe026?d=identicon&s=25 Daniel Harple (Guest)
on 2006-04-10 01:02
(Received via mailing list)
On Apr 10, 2006, at 12:22 AM, Oliver Andrich wrote:
> Paul Battley wrote:
>> URI.join("http://test.de/test1", "test2").to_s #=>
>> "http://test.de/test2"
>
> Can you explain to me why this is correct? I would expect
> http://test.de/test1/test2 as the result of your call.

Think of it this way --

You are in your web-browser on http://test.de/test1. There is a link
to "test2":

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

Would you expect it to go to http://test.de/test1/test2? No, it would
go to http://test.de/test2.

You want:

URI.join("http://test.de/test1/", "test2")
                               ^
URI.join("http://test.de/", "test1/", "test2")
                                   ^

-- Daniel
2abf5beb51d5d66211d525a72c5cb39d?d=identicon&s=25 Paul Battley (Guest)
on 2006-04-10 10:01
(Received via mailing list)
> Can you explain to me why this is correct? I would expect
> http://test.de/test1/test2 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.
92324d1a212698587be6a5f349c7a9b4?d=identicon&s=25 Oliver (Guest)
on 2006-04-10 10:12
Paul Battley wrote:
>> Can you explain to me why this is correct? I would expect
>> http://test.de/test1/test2 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
This topic is locked and can not be replied to.