head: use OsStringExt::from_vec instead of std::from_utf8_unchecked

This no longer triggers the `invalid_from_utf8_unchecked` lint. It
is also a bit cleaner and no longer requires `unsafe` because
OsString is not guaranteed to be valid UTF-8.
This commit is contained in:
Terts Diepraam 2023-05-31 20:09:26 +02:00 committed by Sylvestre Ledru
parent 701f30a15e
commit 77e183955b

View file

@ -622,12 +622,10 @@ mod tests {
#[test]
#[cfg(target_os = "linux")]
fn test_arg_iterate_bad_encoding() {
#[allow(clippy::invalid_utf8_in_unchecked)]
let invalid = unsafe { std::str::from_utf8_unchecked(b"\x80\x81") };
use std::os::unix::ffi::OsStringExt;
let invalid = OsString::from_vec(vec![b'\x80', b'\x81']);
// this arises from a conversion from OsString to &str
assert!(
arg_iterate(vec![OsString::from("head"), OsString::from(invalid)].into_iter()).is_err()
);
assert!(arg_iterate(vec![OsString::from("head"), invalid].into_iter()).is_err());
}
#[test]
fn read_early_exit() {