diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index 311aa3af9..05a30a8eb 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -310,7 +310,8 @@ impl StrUtils for str { } fn fnmatch(&self, pat: &str) -> bool { - parse_glob::from_str(pat).unwrap().matches(self) + // An invalid glob never matches (GNU ignores it); don't unwrap the Err. + parse_glob::from_str(pat).is_ok_and(|glob| glob.matches(self)) } } diff --git a/tests/by-util/test_dircolors.rs b/tests/by-util/test_dircolors.rs index 2be2671af..871151fe3 100644 --- a/tests/by-util/test_dircolors.rs +++ b/tests/by-util/test_dircolors.rs @@ -254,3 +254,12 @@ fn test_colorterm_empty_with_wildcard() { .succeeds() .stdout_only("LS_COLORS='';\nexport LS_COLORS\n"); } + +#[test] +fn test_invalid_term_glob() { + new_ucmd!() + .pipe_in("TERM [\nDIR 01;34\n") + .args(&["-b", "-"]) + .succeeds() + .stdout_only("LS_COLORS='';\nexport LS_COLORS\n"); +}