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

Make os::make_absolute logic available for arbitrary Paths #5003

Closed
mitsuhiko opened this issue Feb 18, 2013 · 13 comments
Closed

Make os::make_absolute logic available for arbitrary Paths #5003

mitsuhiko opened this issue Feb 18, 2013 · 13 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@mitsuhiko
Copy link
Contributor

Especially in web applications (or other apps that do not use the current working directory of the operating system) it would be useful to be able to use make_absolute against an arbitrary path. In Python that's provided by os.path.join. Unfortunately that also comes with negative security aspects (if the right hand side is absolute).

I would propose a Path::unsafe_join function that works like the Python one. As an extension it would also make sense to further improve how joining works for Windows.

Example implementation: https://gist.github.com/mitsuhiko/4974499

@mitsuhiko
Copy link
Contributor Author

The current path joining logic is also broken for Windows. I started work on this in a separate pull request: #5023

@alexcrichton
Copy link
Member

You probably have a much better idea of the scope of this than I do. How much of this is left to be done after your pull request?

@emberian
Copy link
Member

emberian commented Aug 1, 2013

I think path needs to be reworked a bit to do more than just filesystems, but I'm not sure how abstract it can get and not be useless.

@catamorphism
Copy link
Contributor

clearing milestone - won't break backwards-compatibility

@lilyball
Copy link
Contributor

My Path rewrite provides .join() functionality, but it doesn't do the relative testing that you seem to want. You can, however, check something like Path::new(".").is_ancestor_of(proposedRelativePath) to make sure that, not only is it relative, but it doesn't start with ../.

@lilyball
Copy link
Contributor

The path stuff just landed in 40180cd. A relative-path-checking variant of path.join() can be written pretty easily, as I said above, but I don't think we need to provide such functionality in libstd.

@flaper87
Copy link
Contributor

flaper87 commented May 6, 2014

Visiting for triage.

Path has been rewritten and this sounds like doable in a saner way.

@l0kod
Copy link
Contributor

l0kod commented Feb 10, 2015

cc #16507

@steveklabnik
Copy link
Member

@alexcrichton how did this turn out with the Path RFC?

@alexcrichton
Copy link
Member

We've removed make_absolute essentially and this would be an addition to the Path API (e.g. would require an RFC).

@l0kod
Copy link
Contributor

l0kod commented Feb 16, 2015

Why does make_absolute was removed? It should be useful to be able to set a Path as always absolute.

Like said @mitsuhiko, the current join is dangerous and should be replaced with something else (e.g. splice).

@l0kod
Copy link
Contributor

l0kod commented Feb 23, 2015

Normalization for paths is motioned in #22500.

However there seems to be nothing about unsafe join.
Something like AsPath::nest(&self, path: &AsPath) -> PathBuf could be a safe alternative to Path::join() and PathBuf::push().

@alexcrichton
Copy link
Member

This function ended up being removed, so I'm going to close this in favor of a to-be-opened RFC issue to include this functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

9 participants