Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relativeTo issue with empty folder #230

Open
fxOne opened this issue Jul 8, 2015 · 5 comments
Open

relativeTo issue with empty folder #230

fxOne opened this issue Jul 8, 2015 · 5 comments

Comments

@fxOne
Copy link

fxOne commented Jul 8, 2015

I have an issue with generating an relative url where the current browsers url contains an empty folder:

history.pushState(null,'test','/a//c/d') // browser path: example.com/a//c/d
var uri = new URI('http://example.com/a').relativeTo(new URI()) // uri = "../../a"
history.pushState(null,'test2',uri.toString()) // browser path: example.com/a/a

The problem is that normalizePath convert '/a//c/d' to '/a/c/d'. Maybe you can find a solution for me?

@rodneyrehm
Copy link
Member

All clients I know translate /{2,} to /, meaning /// gets normalized to /. I've always considered a//b the result of a bad join operation (e.g. "a/" + "/" + "b").

I have not found anything in RFC 3986 that mandates this behavior. In fact I have not found any mention of // in the path segment aside from section 3.3 saying:

If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//").

Here's a good summary on the behavior of // in paths in Linux. It is also the way Python normalizes paths. Exactly the behavior URI.js show.


Maybe we should talk about the semantics of your a//b/c thing. What's the reason you're using // in there?

@fxOne
Copy link
Author

fxOne commented Jul 10, 2015

Well you are right, currently i have the // because of a bug in an other place of our routing and we are trying to remove it, which should also solve the problem. Also you are right that // should not be used and looks wired.

So far I tested the code i posted in Chrome and was surprised to get example.com/a/a as a result instead of the expected example.com/a.

So far i noticed the also google used the // as you can see here: http://static.googleusercontent.com/media/www.google.com/en//webmasters/docs/search-engine-optimization-starter-guide.pdf
If you remove in the link the // it wont work.

@rodneyrehm
Copy link
Member

Does that mean we can close this issue now?

@fxOne
Copy link
Author

fxOne commented Jul 10, 2015

Feel free to close this ticket, as I found the solution for me to use absolute URIs,which works for our project.
But I would say that relativeTo does not work correct at least in Chrome as you can see in my example.

@rodneyrehm
Copy link
Member

using the url resolution of URL in Chrome I can see the following happening, suggesting that URI.js may indeed be a bit overzealous in normalizing paths:

var url = new URL('../../d', 'https://google.com/a//b/c');
ulr.pathname === '/a/d'

where URI.js behaves as follows:

var url = new URI('../../d', 'https://google.com/a/b/c');
url.pathname() === '/d'

Simply removing the /-deduplication in .normalizePath() breaks existing tests. I'm not sure how to go about this properly and will leave it open for discussion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants