Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upstdlib Path has inconsistent normalisation behaviour #29008
Comments
This comment has been minimized.
This comment has been minimized.
Result:
This one contradicts the docs for pop https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.pop
|
This comment has been minimized.
This comment has been minimized.
|
cc @aturon |
This comment has been minimized.
This comment has been minimized.
|
This one surprised me a lot (and wasted a fair amount of time)!
http://is.gd/yli8ls
|
aidanhs
changed the title
No way to strip a trailing empty path component
stdlib Path has inconsistent normalisation behaviour
Oct 18, 2015
This comment has been minimized.
This comment has been minimized.
|
I'm pretty sure it's a bug if the implementation of |
This comment has been minimized.
This comment has been minimized.
|
I confess, I've not found the edge-case handling of the I'm secretly a bit pleased about the |
alexcrichton
added
the
T-libs
label
Oct 18, 2015
This comment has been minimized.
This comment has been minimized.
|
triage: I-nominated |
rust-highfive
added
the
I-nominated
label
Oct 18, 2015
This comment has been minimized.
This comment has been minimized.
|
triage: P-high |
rust-highfive
added
P-high
and removed
I-nominated
labels
Oct 28, 2015
This comment has been minimized.
This comment has been minimized.
|
seems like we should fix the Hash/Eq situation at the very least |
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Oct 29, 2015
alexcrichton
referenced this issue
Oct 29, 2015
Merged
std: Base Hash for Path on its iterator #29456
bors
added a commit
that referenced
this issue
Nov 2, 2015
This comment has been minimized.
This comment has been minimized.
|
Thanks @alexcrichton for taking care of the hash issue -- it's an interesting footgun with derive. Regarding the semantic/normalization issues: there's definitely disagreement with the docs here, which is bad (and indicates insufficient unit testing). The question about trailing In any case, I agree that the behavior here is counterintuitive and there are cases where you want trailing If the APIs weren't stable, I'd suggest treating The behavior of All that said, I'm not sure what's best to do given the stable status of these APIs. We should definitely discuss this at the next libs team meeting. |
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Nov 2, 2015
bors
added a commit
that referenced
this issue
Nov 2, 2015
This comment has been minimized.
This comment has been minimized.
|
Just focusing on the trailing slash aspect of this issue. Some notes on using
As much as I hate to admit it, I think treating trailing slashes as meaningful in terms of components is probably outvoted (especially since this behaviour is stable). So: document trailing slashes being ignored as part of Python 2:
C++ (boost 1.59):
Tcl 8.5
Ruby 2.2
Nodejs 5
Java 1.8
PHP 5.6
Go
|
arcnmx
added a commit
to arcnmx/rust
that referenced
this issue
Nov 4, 2015
aturon
self-assigned this
Nov 18, 2015
This comment has been minimized.
This comment has been minimized.
|
@aturon is going to send a PR about docs to clarify trailing slash behavior and some of the other issues going on here. |
This comment has been minimized.
This comment has been minimized.
jminer
commented
Jan 9, 2016
|
.NET handles it like Python and C++, which does seem like more useful behavior: https://msdn.microsoft.com/en-us/library/system.io.path.getfilename%28v=vs.110%29.aspx
|
This comment has been minimized.
This comment has been minimized.
|
The stdlib Python 3
|
aturon
added
P-medium
and removed
P-high
labels
Feb 10, 2016
brson
added
A-libs
P-low
labels
Aug 25, 2016
brson
added
E-easy
and removed
P-medium
labels
Aug 25, 2016
This comment has been minimized.
This comment has been minimized.
|
Just needs to update docs pr @aturon's last comment. |
aidanhs commentedOct 13, 2015
Given:
You get:
http://is.gd/XbyUdj
First, the documentation is misleading (wrong?).
file_name(https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.file_name) is documented as "The final component of the path, if it is a normal file.", but it's returning the directory when there's a trailing slash, which is not (by my book) a normal file?Looking at the implementation of
componentsit will return the final component of the path unless it is the root directory or a relative component. Maybe it just needs clarifying.There's a stranger issue with normalisation of trailing slashes. Initially I thought it should be documented (https://doc.rust-lang.org/std/path/index.html#normalization), because trailing slashes are ignored by
components(). However, unlike any other normalisation, it is possible to reconstruct the original path (by doing.push(""))!I'm unsure what the intended behaviour is here and what needs fixing (implementation or docs).
Given stabilisation, I'm going to assume that implemented behaviour wins at this point? It's slightly irritating because being able to detect a trailing slash can be useful (as rsync does). Failing that I might be tempted to make
.push("")do nothing - this uncertain state with trailing slashes is strange. Is there an RFC I can look at maybe?