1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

dircolors: fix empty COLORTERM matching with ?* pattern

should fix tests/misc/dircolors
This commit is contained in:
Sylvestre Ledru 2025-01-07 22:33:57 +01:00
parent 1ffb6fd5b1
commit 1db2e2356a
2 changed files with 25 additions and 1 deletions

View file

@ -374,6 +374,7 @@ where
let term = env::var("TERM").unwrap_or_else(|_| "none".to_owned()); let term = env::var("TERM").unwrap_or_else(|_| "none".to_owned());
let term = term.as_str(); let term = term.as_str();
let colorterm = env::var("COLORTERM").unwrap_or_default();
let mut state = ParseState::Global; let mut state = ParseState::Global;
@ -396,8 +397,20 @@ where
)); ));
} }
let lower = key.to_lowercase(); let lower = key.to_lowercase();
if lower == "term" || lower == "colorterm" { if lower == "term" || lower == "colorterm" {
if term.fnmatch(val) { let should_match = if lower == "colorterm" {
// For COLORTERM ?*, only match if COLORTERM is non-empty
if val == "?*" {
!colorterm.is_empty()
} else {
colorterm.fnmatch(val)
}
} else {
term.fnmatch(val)
};
if should_match {
state = ParseState::Matched; state = ParseState::Matched;
} else if state != ParseState::Matched { } else if state != ParseState::Matched {
state = ParseState::Pass; state = ParseState::Pass;

View file

@ -253,3 +253,14 @@ fn test_repeated() {
new_ucmd!().arg(arg).arg(arg).succeeds().no_stderr(); new_ucmd!().arg(arg).arg(arg).succeeds().no_stderr();
} }
} }
#[test]
fn test_colorterm_empty_with_wildcard() {
new_ucmd!()
.env("COLORTERM", "")
.pipe_in("COLORTERM ?*\nowt 40;33\n")
.args(&["-b", "-"])
.succeeds()
.stdout_is("LS_COLORS='';\nexport LS_COLORS\n")
.no_stderr();
}