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

canonical-path: CanonicalPath::join() should canonicalize. #547

Open
sethfowler opened this issue Oct 28, 2020 · 0 comments
Open

canonical-path: CanonicalPath::join() should canonicalize. #547

sethfowler opened this issue Oct 28, 2020 · 0 comments

Comments

@sethfowler
Copy link

sethfowler commented Oct 28, 2020

Nice library! It's quite useful.

I did run into an issue, though. My expectation was that this pseudo-code should work:

let ref_path = CanonicalPath::new("/foo/bar/").unwrap();
let relative_path = Path::new("../baz");
let abs_path = ref_path.join(&relative_path).expect("This should succeed!");
assert_eq!(CanonicalPath::new("/foo/baz"), abs_path);

In reality, the call to join() fails. This happens because relative_path contains ../ and CanonicalPath::join() just concatenates the two paths and calls CanonicalPathBuf::new(). Since CanonicalPathBuf::new() returns Err if the path is not already canonical, CanonicalPath::join() does as well. If CanonicalPath::join() called CanonicalPathBuf::canonicalize() instead, then this code would work as expected.

For now, I'm using this approach as a workaround:

let abs_path = CanonicalPathBuf::canonicalize(ref_path.as_path().join(&relative_path));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant