mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #4861 from sylvestre/ls-invalid-utf8
ls: when facing an invalid utf-8, don't panic
This commit is contained in:
commit
caaf25a003
2 changed files with 20 additions and 1 deletions
|
@ -1997,7 +1997,12 @@ fn should_display(entry: &DirEntry, config: &Config) -> bool {
|
|||
require_literal_separator: false,
|
||||
case_sensitive: true,
|
||||
};
|
||||
let file_name = entry.file_name().into_string().unwrap();
|
||||
let file_name = entry.file_name();
|
||||
// If the decoding fails, still show an incorrect rendering
|
||||
let file_name = match file_name.to_str() {
|
||||
Some(s) => s.to_string(),
|
||||
None => file_name.to_string_lossy().into_owned(),
|
||||
};
|
||||
!config
|
||||
.ignore_patterns
|
||||
.iter()
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue