Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Bugs with route_to #3

mjwillson opened this Issue · 0 comments

2 participants


OK so there are multiple problems with this example:

irb(main):106:0> a = Addressable::URI.parse("")
=> #<Addressable::URI:0x80e53910 URI:>
irb(main):107:0> b = Addressable::URI.parse("")
=> #<Addressable::URI:0x80e4fd10 URI:>
irb(main):108:0> a.route_to(b)
=> #<Addressable::URI:0x80e4a720 URI:/baz>

/baz as a relative URL from a base of would point to, not as asked for.

irb(main):109:0> a.join(a.route_to(b))
=> #<Addressable::URI:0x80e45b94 URI:>

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 == ?
Turns out that b.normalize has gone a bit funny

irb(main):111:0> b
=> #<Addressable::URI:0x80e4fd10 URI:>
rb(main):118:0> b.normalize
=> #<Addressable::URI:0x80e29548 URI:>

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("")
=> #<Addressable::URI:0x80e25754 URI:>
irb(main):120:0> b.normalize
=> #<Addressable::URI:0x80e2333c URI:>

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.