diff options
| author | bors <bors@rust-lang.org> | 2024-05-27 14:45:56 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-05-27 14:45:56 +0000 |
| commit | 79c30b69e4aefaccffcdab8ae70886ef87bf0a43 (patch) | |
| tree | 45f5a4dbd04fea2797846e26920e08dbd26d73db /library/std/src/path.rs | |
| parent | da6c08e8652d112dc1d44e985842684a4b50bd12 (diff) | |
| parent | 84f70abacb2a9a0d6d90435b44ba69c71147e34c (diff) | |
| download | rust-79c30b69e4aefaccffcdab8ae70886ef87bf0a43.tar.gz rust-79c30b69e4aefaccffcdab8ae70886ef87bf0a43.zip | |
Auto merge of #3635 - RalfJung:rustup, r=RalfJung
Rustup
Diffstat (limited to 'library/std/src/path.rs')
| -rw-r--r-- | library/std/src/path.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/library/std/src/path.rs b/library/std/src/path.rs index f835b69f0cf..f4e1e2a38c1 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -1425,6 +1425,11 @@ impl PathBuf { /// If `extension` is the empty string, [`self.extension`] will be [`None`] /// afterwards, not `Some("")`. /// + /// # Panics + /// + /// Panics if the passed extension contains a path separator (see + /// [`is_separator`]). + /// /// # Caveats /// /// The new `extension` may contain dots and will be used in its entirety, @@ -1470,6 +1475,14 @@ impl PathBuf { } fn _set_extension(&mut self, extension: &OsStr) -> bool { + for &b in extension.as_encoded_bytes() { + if b < 128 { + if is_separator(b as char) { + panic!("extension cannot contain path separators: {:?}", extension); + } + } + } + let file_stem = match self.file_stem() { None => return false, Some(f) => f.as_encoded_bytes(), |
