Repository: sharkdp/fd (language: rust)

Issue:
Invalid utf8 filenames displayed when '-e' is used
``` bash
> touch $(printf 'invalid_\xFE.txt')
> fd -e zip
invalid_�.txt
```


Discussion / hints:

Fix patch:
diff --git a/src/walk.rs b/src/walk.rs
index bbb6144aa..954a978e1 100644
--- a/src/walk.rs
+++ b/src/walk.rs
@@ -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;
                 }
             }
 


Test patch:
diff --git a/tests/tests.rs b/tests/tests.rs
index 084683a2e..7e0e8dcdd 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -887,3 +887,27 @@ fn test_fixed_strings() {
     // Combine with --case-sensitive
     te.assert_output(&["--fixed-strings", "--case-sensitive", "download (1)"], "");
 }
+
+/// Filenames with invalid UTF-8 sequences
+#[cfg(target_os = "linux")]
+#[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_�invalid.txt");
+
+    te.assert_output(&["invalid", "test1/"], "test1/test_�invalid.txt");
+
+    // Should not be found under a different extension
+    te.assert_output(&["-e", "zip", "", "test1/"], "");
+}