Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Dubious .relativeTo behaviour #75

Closed
djcsdy opened this Issue · 0 comments

1 participant

@djcsdy
URI("http://example.org/foo/bar/bat").
    relativeTo("http://example.org/").
    toString()
// => "http://example.org/foo/bar/bat"

I think this should return "foo/bar/bat" (preferably) or "./foo/bar/bat" (if you must, but see below).

URI("http://example.org/foo/bar/bat").
    relativeTo("http://example.org/foo").
    toString()
// => "../bar/bat"

Since we’re resolving relative to a URL whose path doesn’t end with a slash, foo shouldn’t be treated as a directory, so I think this should return the same result as for the first example above. Even if we do (incorrectly) treat foo as a directory, this result doesn’t make any sense.

URI("http://example.com/foo/bar/bat").
    relativeTo("http://example.org/foo/").
    toString()
// => "./bar/bat"

I think this should return "//example.com/foo/bar/bat" (note that example.com and example.org are different; the only URI component in common is the http scheme).

URI("http://example.org/foo/bar/bat").
    relativeTo("http://example.org/foo/").
    toString()
// => "./bar/bat"

This is correct but the ./ is redundant so the resulting URL is not normalized. I feel like relativeTo would be more useful if it did not insert redundant dot segments. For instance, I want to be able to relativize a URL with respect to the root URL of my application, and then iterate through segment() to route a request to the correct controller. The current implementation obliges me to do extra work to remove the dot segment :(.

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.