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>
This commit is contained in:
commit
62da4ab161
2 changed files with 5 additions and 1 deletions
|
@ -1208,6 +1208,9 @@ impl PathBuf {
|
||||||
/// * if `path` has a root but no prefix (e.g., `\windows`), it
|
/// * if `path` has a root but no prefix (e.g., `\windows`), it
|
||||||
/// replaces everything except for the prefix (if any) of `self`.
|
/// replaces everything except for the prefix (if any) of `self`.
|
||||||
/// * if `path` has a prefix but no root, it replaces `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
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
@ -1254,7 +1257,7 @@ impl PathBuf {
|
||||||
self.as_mut_vec().truncate(0);
|
self.as_mut_vec().truncate(0);
|
||||||
|
|
||||||
// verbatim paths need . and .. removed
|
// 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();
|
let mut buf: Vec<_> = comps.collect();
|
||||||
for c in path.components() {
|
for c in path.components() {
|
||||||
match c {
|
match c {
|
||||||
|
|
|
@ -1271,6 +1271,7 @@ pub fn test_push() {
|
||||||
tp!(r"\\?\A:\x\y", "/foo", r"\\?\A:\foo");
|
tp!(r"\\?\A:\x\y", "/foo", r"\\?\A:\foo");
|
||||||
tp!(r"\\?\A:", r"..\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".\foo\.", r"\\?\A:\x\y\foo");
|
||||||
|
tp!(r"\\?\A:\x\y", r"", r"\\?\A:\x\y\");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue