Rollup merge of #126305 - workingjubilee:fix-os-string-to-string-utf8… · model-checking/verify-rust-std@6ec98e7 (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -477,6 +477,9 @@ impl Wtf8Buf {
477 477 /// Part of a hack to make PathBuf::push/pop more efficient.
478 478 #[inline]
479 479 pub(crate) fn as_mut_vec_for_path_buf(&mut self) -> &mut Vec<u8> {
480 +// FIXME: this function should not even exist, as it implies violating Wtf8Buf invariants
481 +// For now, simply assume that is about to happen.
482 +self.is_known_utf8 = false;
480 483 &mut self.bytes
481 484 }
482 485 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
1 +#![cfg(windows)]
2 +//! An external tests
3 +
4 +use std::{ffi::OsString, os::windows::ffi::OsStringExt, path::PathBuf};
5 +
6 +#[test]
7 +#[should_panic]
8 +fn os_string_must_know_it_isnt_utf8_issue_126291() {
9 +let mut utf8 = PathBuf::from(OsString::from("utf8".to_owned()));
10 +let non_utf8: OsString =
11 +OsStringExt::from_wide(&[0x6e, 0x6f, 0x6e, 0xd800, 0x75, 0x74, 0x66, 0x38]);
12 + utf8.set_extension(&non_utf8);
13 + utf8.into_os_string().into_string().unwrap();
14 +}