mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +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]
|
#[test]
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn test_arg_iterate_bad_encoding() {
|
fn test_arg_iterate_bad_encoding() {
|
||||||
#[allow(clippy::invalid_utf8_in_unchecked)]
|
use std::os::unix::ffi::OsStringExt;
|
||||||
let invalid = unsafe { std::str::from_utf8_unchecked(b"\x80\x81") };
|
let invalid = OsString::from_vec(vec![b'\x80', b'\x81']);
|
||||||
// this arises from a conversion from OsString to &str
|
// this arises from a conversion from OsString to &str
|
||||||
assert!(
|
assert!(arg_iterate(vec![OsString::from("head"), invalid].into_iter()).is_err());
|
||||||
arg_iterate(vec![OsString::from("head"), OsString::from(invalid)].into_iter()).is_err()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn read_early_exit() {
|
fn read_early_exit() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue