diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2021-10-22 19:42:43 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-22 19:42:43 +0900 |
| commit | 62da4ab161fc74bf378051ea006b29f6ec94a764 (patch) | |
| tree | d1d351f4987dc68bd2f8333327781b6e1bf2d959 | |
| parent | 8738d5d61183e7fec36b8645586f148ec36d82c3 (diff) | |
| parent | 1bb399c3420038d54a1eda799a941e77ccd61a05 (diff) | |
| download | rust-62da4ab161fc74bf378051ea006b29f6ec94a764.tar.gz rust-62da4ab161fc74bf378051ea006b29f6ec94a764.zip | |
Rollup merge of #89665 - seanyoung:push-empty, r=m-ou-se
Ensure that pushing empty path works as before on verbatim paths Fixes: https://github.com/rust-lang/rust/issues/89658 Signed-off-by: Sean Young <sean@mess.org>
| -rw-r--r-- | library/std/src/path.rs | 5 | ||||
| -rw-r--r-- | library/std/src/path/tests.rs | 1 |
2 files changed, 5 insertions, 1 deletions
diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 47156dc33e5..8f00d2260e4 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -1208,6 +1208,9 @@ impl PathBuf { /// * if `path` has a root but no prefix (e.g., `\windows`), it /// replaces everything except for the prefix (if any) of `self`. /// * if `path` has a prefix but no root, it replaces `self`. + /// * if `self` has a verbatim prefix (e.g. `\\?\C:\windows`) + /// and `path` is not empty, the new path is normalized: all references + /// to `.` and `..` are removed. /// /// # Examples /// @@ -1254,7 +1257,7 @@ impl PathBuf { self.as_mut_vec().truncate(0); // verbatim paths need . and .. removed - } else if comps.prefix_verbatim() { + } else if comps.prefix_verbatim() && !path.inner.is_empty() { let mut buf: Vec<_> = comps.collect(); for c in path.components() { match c { diff --git a/library/std/src/path/tests.rs b/library/std/src/path/tests.rs index 3973a6829d3..0a16ff2a721 100644 --- a/library/std/src/path/tests.rs +++ b/library/std/src/path/tests.rs @@ -1271,6 +1271,7 @@ pub fn test_push() { tp!(r"\\?\A:\x\y", "/foo", r"\\?\A:\foo"); tp!(r"\\?\A:", r"..\foo\.", r"\\?\A:\foo"); tp!(r"\\?\A:\x\y", r".\foo\.", r"\\?\A:\x\y\foo"); + tp!(r"\\?\A:\x\y", r"", r"\\?\A:\x\y\"); } } |
