OK so there are multiple problems with this example:
irb(main):106:0> a = Addressable::URI.parse("http://foo.com/bar")
=> #<Addressable::URI:0x80e53910 URI:http://foo.com/bar>
irb(main):107:0> b = Addressable::URI.parse("http://foo.com/bar/baz")
=> #<Addressable::URI:0x80e4fd10 URI:http://foo.com/bar/baz>
irb(main):108:0> a.route_to(b)
=> #<Addressable::URI:0x80e4a720 URI:/baz>
/baz as a relative URL from a base of http://foo.com/bar would point to http://foo.com/baz, not http://foo.com/bar/baz as asked for.
irb(main):109:0> a.join(a.route_to(b))
=> #<Addressable::URI:0x80e45b94 URI:http://foo.com/baz>
So this is wrong, and breaks the expected invariant "a.join(a.route_to(b)) == b".
Or so you'd think, except look at this:
irb(main):110:0> a.join(a.route_to(b)) == b
=> true
How does http://foo.com/baz == http://foo.com/bar/baz ?
Turns out that b.normalize has gone a bit funny
irb(main):111:0> b
=> #<Addressable::URI:0x80e4fd10 URI:http://foo.com/bar/baz>
rb(main):118:0> b.normalize
=> #<Addressable::URI:0x80e29548 URI:http://foo.com/baz>
Seems like a state-related bug; seems calling "a.route_to(b)" has an unwanted side-effect on b. If I parse b afresh, this doesn't happen.
irb(main):119:0> b = Addressable::URI.parse("http://foo.com/bar/baz")
=> #<Addressable::URI:0x80e25754 URI:http://foo.com/bar/baz>
irb(main):120:0> b.normalize
=> #<Addressable::URI:0x80e2333c URI:http://foo.com/bar/baz>
So yeah there's this state bug, and there's the fact it gave me the wrong relative URL.
Another thing is, it would be really nice if "route_to" could work with relative URLs as the start / endpoints, eg if stuff like this worked
Addressable::URI.parse("/foo/bar").route_to("/foo/baz") == Addressable::URI.parse("baz")
Addressable::URI.parse("/foo/bar/baz").route_to("/foo/boo") == Addressable::URI.parse("../boo")
but realise this raises some issues.
eg currently 'normalize' removes information from some kinds of relative URI:
irb(main):142:0> Addressable::URI.parse("../boo").normalize
=> #<Addressable::URI:0x80b0ae70 URI:boo>
after normalization this now would behave differently with 'join'