Skip invalid utf8 filenames, closes #250

This commit is contained in:
sharkdp 2018-02-25 23:37:59 +01:00 committed by David Peter
parent 631931b431
commit 47d95284aa
2 changed files with 25 additions and 0 deletions

View File

@ -217,6 +217,8 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) {
if !exts_regex.is_match(path_str) {
return ignore::WalkState::Continue;
}
} else {
return ignore::WalkState::Continue;
}
}

View File

@ -887,3 +887,26 @@ fn test_fixed_strings() {
// Combine with --case-sensitive
te.assert_output(&["--fixed-strings", "--case-sensitive", "download (1)"], "");
}
/// Filenames with invalid UTF-8 sequences
#[test]
fn test_invalid_utf8() {
use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt;
let dirs = &["test1"];
let files = &[];
let te = TestEnv::new(dirs, files);
fs::File::create(
te.test_root()
.join(OsStr::from_bytes(b"test1/test_\xFEinvalid.txt")),
).unwrap();
te.assert_output(&["", "test1/"], "test1/test_<74>invalid.txt");
te.assert_output(&["invalid", "test1/"], "test1/test_<74>invalid.txt");
// Should not be found under a different extension
te.assert_output(&["-e", "zip", "", "test1/"], "");
}