You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] case matches a quoted pattern as a glob (case abc in "a*") matches) #327
A quoted pattern, or the quoted part of one, matches literally, as in bash:
nomatch
nomatch
nomatch
same
Actual Behavior
matched
matched
matched
differ
The wrong arm runs with no diagnostic. A value compared with itself fails to match when it contains [.
Additional Context
Found while reviewing #325. It is not caused by that PR. I ran a debug build of 4b0bdbc through -c; src/exec.rs and src/parser.rs are identical at main @ 9455e9f.
execute_case (src/exec.rs:2738-2739) expands the pattern with expand_word, which returns a plain string, so the quoting is gone before case_match sees it:
let pattern = expand_word(os.clone(), proc, pat).await;ifcase_match(&pattern,&value){
Possible Solution
glob_match (src/exec.rs) has no escape syntax, so there is no way to hand it a literal *, ? or [. Two options: give glob_match backslash escapes and have the pattern expansion escape the text that came from SingleQuoted/DoubleQuoted parts, or compare with == when every part of the pattern word is quoted (this covers "$x" and 'a*' but not mixed words such as *"$x"*).
Related Issues
#325 ([[ x == "pattern" ]] reuses case_match and has the same gap)
Activity
test: cover backslashes, brackets and tilde in case patterns (strands…
test: cover escaped range endpoints in case patterns (strands-agents#327