Skip to content

Match quoted glob chars literally in [[ == ]] patterns (batch87) - #292

Merged
brianjfox merged 1 commit into
mainfrom
fix/testsuite-batch87
Jul 25, 2026
Merged

Match quoted glob chars literally in [[ == ]] patterns (batch87)#292
brianjfox merged 1 commit into
mainfrom
fix/testsuite-batch87

Conversation

@brianjfox

Copy link
Copy Markdown
Owner

Summary

The right-hand side of [[ word == pattern ]] (and !=) is a pattern in which a quoted or backslash-escaped glob metacharacter matches literally, but CondEval expanded it with expand_no_split (quote removal), so the protecting quotes were stripped before strmatch:

$ [[ abc == a\* ]]; echo $?      # was 0 (matched)  → now 1
$ [[ ab == a"*" ]]; echo $?      # was 0            → now 1
$ [[ axb == a"*"b ]]; echo $?    # was 0            → now 1

Fix: expand the ==/!= right-hand side with expand_pattern (which backslash-escapes quoted glob chars while leaving unquoted ones active) — the same expansion the case statement already uses. Active (unquoted) globs still match.

Testing

  • ctest 22/22
  • Scoreboard: cond 79 → 75, comsub2 37 → 35 (bonus), zero regressions
  • Verified quoted/escaped vs active glob (*/?), ==/!=, and literal cases against bash 5.3

Closes #291.

The right-hand side of [[ word == pattern ]] (and !=) is a pattern in which a
quoted or backslash-escaped glob metacharacter matches literally, but CondEval
expanded it with expand_no_split (quote removal), so `[[ abc == a\* ]]' and
`[[ ab == a"*" ]]' wrongly matched as active globs.

Expand the ==/!= right-hand side with expand_pattern instead, which backslash-
escapes quoted glob characters while leaving unquoted ones active -- the same
expansion the case statement already uses.

Closes #291.
@brianjfox
brianjfox merged commit 633aed3 into main Jul 25, 2026
1 check passed
@brianjfox
brianjfox deleted the fix/testsuite-batch87 branch July 25, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[[ == ]] treats quoted/escaped glob metacharacters as active globs

1 participant