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

Uri.resolve and Uri.resolveUri return incorrect results for ".." when the base URI is relative #23809

Closed
nex3 opened this issue Jul 9, 2015 · 8 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io
Milestone

Comments

@nex3
Copy link
Member

nex3 commented Jul 9, 2015

Currently, Uri.parse(".").resolve("../foo").path returns "foo". This is incorrect; . refers to the current path, so anything resolved relative to it should return itself. This means that the example above should return "../foo".

@nex3 nex3 added Type-Defect area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io labels Jul 9, 2015
@nex3
Copy link
Member Author

nex3 commented Jul 9, 2015

Upon further inspection, this goes beyond just .. Any single-component relative URI will ignore any number of leading ../ components in resolve() and resolveUri()

@nex3 nex3 changed the title Uri.resolve and Uri.resolveUri return incorrect results for ".." when the base URI is "." Uri.resolve and Uri.resolveUri return incorrect results for ".." when the base URI is relative Jul 9, 2015
@lrhn lrhn added the Accepted label Jul 10, 2015
@lrhn
Copy link
Member

lrhn commented Jul 10, 2015

The problem is that the resolution algorithm in RFC 3986 is only specified to work for an "absolute" base URI, and for that case, you can't go "above the root", so initial ".." are discarded. (It's not really absolute in the sense that the path needs to start with "/", but nevertheless it acts that way).

We conflate URI (always has a scheme and is considered "complete") and URI-reference (may not have a scheme and is considered to be relative to a base URI) into one class, so we can't easily make the distinction that you can only resolve a URI reference against a base URI.

So, resolving against a relative URI is really unspecified, but I agree that it would be great if it did something useful instead of this.

How about: If the receiver Uri of resolveUri has no scheme (so we are in unspecified territory) and a non-empty relative path (implies that there is also no authority, and it's really just a path), then we allow path merging to result in leading ".." segments. That means that Uri.parse("foo/bar").resolve("../../../baz") would give the path "../baz". If you do Uri.parse("file:foo/bar").resolve("../../../baz") then you still get "file:/baz" as the specification requires.

@floitschG
Copy link
Contributor

Let's do that.

@lrhn
Copy link
Member

lrhn commented Jul 13, 2015

Another problem is that we don't path-normalize the URI from the beginning, and I think we should do that too.
The effect is that if you start with scheme://auth/foo/.. and resolve bar against it, you get scheme://auth/foo/bar. The merge-path algorithm in RFC 3986 makes you drop the last segment of the original path before merging, and it doesn't check if that happens to be "..".

@floitschG
Copy link
Contributor

Agreed. This is something that could drip users. So let's fix it.

@sethladd
Copy link
Contributor

@floitschG should we do this for 1.12 ?

@lrhn
Copy link
Member

lrhn commented Aug 18, 2015

Thanks for asking :)
This was fixed in 848f6c9 which is part of 1.12.

@lrhn lrhn closed this as completed Aug 18, 2015
@sethladd sethladd added this to the 1.12 milestone Aug 18, 2015
@sethladd
Copy link
Contributor

Cool, thanks for the update!

harryterkelsen referenced this issue in dart-lang/package_config Aug 18, 2015
Invalid test cleanup (parse_test) [TBR].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io
Projects
None yet
Development

No branches or pull requests

4 participants