diff options
| author | Jubilee <46493976+workingjubilee@users.noreply.github.com> | 2024-06-12 03:57:25 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-12 03:57:25 -0700 |
| commit | 3862f01655093637ee965e9c893eb14eeaecd739 (patch) | |
| tree | ce9a551bb7b55b7157af47c7761aa362573bd283 | |
| parent | 36e828fab5f8124a146f1b762b36027638372d4a (diff) | |
| parent | af04418a0519d45af1bc41667bffc0c2fce2cef4 (diff) | |
| download | rust-3862f01655093637ee965e9c893eb14eeaecd739.tar.gz rust-3862f01655093637ee965e9c893eb14eeaecd739.zip | |
Rollup merge of #126305 - workingjubilee:fix-os-string-to-string-utf8-invariant, r=joboet
Make PathBuf less Ok with adding UTF-16 then `into_string` Fixes #126291 which is, as far as I can tell, a regression introduced by #96869. try-job: x86_64-msvc
| -rw-r--r-- | library/std/src/sys_common/wtf8.rs | 3 | ||||
| -rw-r--r-- | library/std/tests/windows.rs | 14 |
2 files changed, 17 insertions, 0 deletions
diff --git a/library/std/src/sys_common/wtf8.rs b/library/std/src/sys_common/wtf8.rs index bb1e505285b..84128a4b595 100644 --- a/library/std/src/sys_common/wtf8.rs +++ b/library/std/src/sys_common/wtf8.rs @@ -477,6 +477,9 @@ impl Wtf8Buf { /// Part of a hack to make PathBuf::push/pop more efficient. #[inline] pub(crate) fn as_mut_vec_for_path_buf(&mut self) -> &mut Vec<u8> { + // FIXME: this function should not even exist, as it implies violating Wtf8Buf invariants + // For now, simply assume that is about to happen. + self.is_known_utf8 = false; &mut self.bytes } } diff --git a/library/std/tests/windows.rs b/library/std/tests/windows.rs new file mode 100644 index 00000000000..9f7596f1bc2 --- /dev/null +++ b/library/std/tests/windows.rs @@ -0,0 +1,14 @@ +#![cfg(windows)] +//! An external tests + +use std::{ffi::OsString, os::windows::ffi::OsStringExt, path::PathBuf}; + +#[test] +#[should_panic] +fn os_string_must_know_it_isnt_utf8_issue_126291() { + let mut utf8 = PathBuf::from(OsString::from("utf8".to_owned())); + let non_utf8: OsString = + OsStringExt::from_wide(&[0x6e, 0x6f, 0x6e, 0xd800, 0x75, 0x74, 0x66, 0x38]); + utf8.set_extension(&non_utf8); + utf8.into_os_string().into_string().unwrap(); +} |
