diff options
author | Sylvestre Ledru <sylvestre@debian.org> | 2023-05-14 21:47:58 +0200 |
---|---|---|
committer | Sylvestre Ledru <sylvestre@debian.org> | 2023-05-14 22:11:44 +0200 |
commit | 3e7594632bbdbcb4a299603acef78818160eac2b (patch) | |
tree | 8d979fb003cb8523b0b7684cdefb7a691d3560ee /tests/by-util | |
parent | 49c16a2f11a47f4c63cc2bade695bee231bab8a3 (diff) |
ls: when facing an invalid utf-8, don't panic
Fails with
```
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "invalid-\xE0-"', src/uu/ls/src/ls.rs:1932:53
```
Diffstat (limited to 'tests/by-util')
-rw-r--r-- | tests/by-util/test_ls.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index d460952ed..45ced867a 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -7,6 +7,10 @@ use crate::common::util::TestScenario; use nix::unistd::{close, dup}; use regex::Regex; use std::collections::HashMap; +#[cfg(target_os = "linux")] +use std::ffi::OsStr; +#[cfg(target_os = "linux")] +use std::os::unix::ffi::OsStrExt; #[cfg(all(unix, feature = "chmod"))] use std::os::unix::io::IntoRawFd; use std::path::Path; @@ -3434,3 +3438,13 @@ fn test_device_number() { .succeeds() .stdout_contains(major_minor_str); } + +#[test] +#[cfg(target_os = "linux")] +fn test_invalid_utf8() { + let (at, mut ucmd) = at_and_ucmd!(); + + let filename = OsStr::from_bytes(b"-\xE0-foo"); + at.touch(filename); + ucmd.succeeds(); +} |