mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 07:12:44 +00:00
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:
parent
701f30a15e
commit
77e183955b
1 changed files with 3 additions and 5 deletions
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue