Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 62da4ab

Browse files
authoredOct 22, 2021
Rollup merge of #89665 - seanyoung:push-empty, r=m-ou-se
Ensure that pushing empty path works as before on verbatim paths Fixes: #89658 Signed-off-by: Sean Young <sean@mess.org>
2 parents 8738d5d + 1bb399c commit 62da4ab

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed
 

‎library/std/src/path.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,9 @@ impl PathBuf {
12081208
/// * if `path` has a root but no prefix (e.g., `\windows`), it
12091209
/// replaces everything except for the prefix (if any) of `self`.
12101210
/// * if `path` has a prefix but no root, it replaces `self`.
1211+
/// * if `self` has a verbatim prefix (e.g. `\\?\C:\windows`)
1212+
/// and `path` is not empty, the new path is normalized: all references
1213+
/// to `.` and `..` are removed.
12111214
///
12121215
/// # Examples
12131216
///
@@ -1254,7 +1257,7 @@ impl PathBuf {
12541257
self.as_mut_vec().truncate(0);
12551258

12561259
// verbatim paths need . and .. removed
1257-
} else if comps.prefix_verbatim() {
1260+
} else if comps.prefix_verbatim() && !path.inner.is_empty() {
12581261
let mut buf: Vec<_> = comps.collect();
12591262
for c in path.components() {
12601263
match c {

‎library/std/src/path/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,7 @@ pub fn test_push() {
12711271
tp!(r"\\?\A:\x\y", "/foo", r"\\?\A:\foo");
12721272
tp!(r"\\?\A:", r"..\foo\.", r"\\?\A:\foo");
12731273
tp!(r"\\?\A:\x\y", r".\foo\.", r"\\?\A:\x\y\foo");
1274+
tp!(r"\\?\A:\x\y", r"", r"\\?\A:\x\y\");
12741275
}
12751276
}
12761277

0 commit comments

Comments
 (0)
Failed to load comments.