Repository navigation
fix(case): match quoted parts of a pattern literally - #351
Conversation
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Changes requested. The quoted-pattern fix works and matches bash, but it breaks an unquoted \\ in a case pattern (case $p in *\\*)), which main gets right. The fix is three lines; I built and ran it.
Result at 94da1f4 |
|
|---|---|
Claimed fix: quoted parts literal, both case sites |
✅ matches bash 5.2.15; the new case fails on dbb6189 and passes here |
🔴 Unquoted \\ in a case pattern |
regression: silently takes the wrong arm (inline) |
🟡 Quoted glob char inside [...], e.g. ["*?"] |
regression: the set also matches a backslash (inline) |
| Suites | cargo test --workspace --all-targets: 2733 passed, 0 failed; cargo fmt --check and cargo clippy exit 0 |
What I verified, and non-blocking notes
Verified
- Head
94da1f4, basedbb6189(=main), debug builds of both, oracle bash 5.2.15 on aarch64 Linux. case_quoted_pattern_is_literal.expectedis byte-identical to what bash prints for the.sh(run with the README's empty environment). Base differs on 7 of the 11 lines; head on none.- A 163-script probe corpus, each run directly and inside
$(...)(326 runs), against bash, base and head. Head disagrees with bash where base agrees in 56 runs. All 56 come from three causes: the two inline findings and the tilde note below. - With the candidate fix from the two inline comments applied on top of
94da1f4: 54 of those 56 runs match bash, no run gets worse, andcargo test --workspace --all-targetsis still 2733 passed, 0 failed. The remaining 2 are the tilde case. - Not run:
pytest tests/python,npm test(the change is Rust-only; CI is green for both).
Good side effect worth a test line. An unquoted variable holding a backslash now behaves like bash: x='a\b'; case ab in $x) matches and case 'a\b' in $x) doesn't. main has both backwards. The new case doesn't cover it.
Appendix: non-blocking (4)
- ⚪
expand_patternskips theis_array_literal→refuse_arraycheck thatexpand_wordhas (src/exec.rs:498-501).case x in a=(1 2)) echo z;; esacprintedarrays are not supportedand exited 2 onmain; here it's silent and exits 0. It's a syntax error in bash, so only the loud refusal is lost. - ⚪ Tilde output isn't escaped:
HOME='/tmp/a\b'; case '/tmp/a\b' in ~)matches in bash and onmain, not here. AddingWordPart::Tilde(_)to the quoted arm should cover it (not built). - ⚪ Same on
mainand here, so not from this PR: quotes nested in an expansion still glob (unset u; case abc in ${u:-"a*"})matches; bash doesn't). - ⚪ Same on
mainand here: quoted!,^,-,]inside a bracket keep their special meaning (case b in ["!"a])matches; bash doesn't).
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Approved at d26b9cc. Both findings from my last review are fixed and verified. One rare regression is left, and it comes from the bracket code I suggested.
| Previous finding | Status at d26b9cc |
|---|---|
🔴 Unquoted \\ in a case pattern |
fixed: the repro matches bash, and [[ $p == *\\* ]] now does too |
🟡 Quoted glob char inside [...] |
fixed, but ranges with an escaped endpoint ([A-\\], ["*"-z]) broke (new 🟡, inline) |
| ⚪ Tilde output, array-literal refusal | both behave like main again |
The new 🟡 needs unusual input, so I'm not blocking on it. The inline comment has a fix I built and ran, if you want it in this PR.
What I verified, and non-blocking notes
Verified
- Head
d26b9cc, basedbb6189(=main), debug builds, oracle bash 5.2.15 on aarch64 Linux. cargo test --workspace --all-targets: 2733 passed, 0 failed.cargo fmt --checkandcargo clippy --workspace --all-targetsexit 0. CI is green.case_quoted_pattern_is_literal.expectedis byte-identical to what bash prints for the.sh(23 lines, README's empty environment).dbb6189differs on 9 lines,94da1f4on 7,d26b9ccon none.- Both repro scripts from my first review match bash line for line.
- The 326-run probe corpus from the first review: the 56 runs that regressed at
94da1f4all match bash now, and no run got worse. - The array refusal is back:
case x in a=(1 2)) echo z;; esacprintsarrays are not supportedand exits 2, as onmain. - 75 new scripts aimed at this delta (backslash before various characters, brackets, tilde, the
[[ ]]path), each run directly and inside$(...). Two causes differ from bash wheremainagrees: the range finding inline, and the note below. - Not run:
pytest tests/python,npm test.
Appendix: non-blocking (1)
- ⚪ An unquoted
\\inside a${...}default is still read as an escape:unset u; case 'a\b' in ${u:-a\\b})matches in bash and onmain, not here (same at94da1f4). TheLiteralfix only looks at top-level parts. I don't expect real scripts to hit this.
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Approved at ed589e4. The range-endpoint finding is fixed and verified, and this round turned up nothing new in the change.
| Previous finding | Status at ed589e4 |
|---|---|
| 🟡 Bracket range with an escaped endpoint | fixed: all nine repro lines match bash, in case and in [[ ]] |
⚪ \\ inside a ${u:-a\\b} default |
unchanged by choice; still the only place I found where this PR is worse than main |
Deferring the ⚪ is fine by me. It needs the same nested-quoting information as ${u:-"a*"}, which is already wrong on main, so the two are best fixed together.
What I verified
- Head
ed589e4, basedbb6189(=main), debug builds, oracle bash 5.2.15 on aarch64 Linux. src/exec.rsated589e4is byte-identical to the build I tested last round (blob6f352e0).cargo test --workspace --all-targets: 2733 passed, 0 failed.cargo fmt --checkandcargo clippy --workspace --all-targetsexit 0.case_quoted_pattern_is_literal.expectedis byte-identical to what bash prints for the.sh(30 lines).d26b9ccdiffers on 4 lines,ed589e4on none.- The repro scripts from all three inline comments match bash line for line.
- Probe scripts, each run directly and inside
$(...): the 163 from round one, the 75 from round two, and 52 new ones on bracket forms ([]a],[!]a],[a-], ranges with escaped endpoints, unquoted variables holding\) plus callers that use the matcher with escapes off (${x#[a-c]},${x%%[0-9]*}). The only runs wheremainagrees with bash and this branch doesn't are the two for${u:-a\\b}. - CI: every build and test job and
CI Gatesucceeded. The rollup shows red only because one duplicate2 Approvers for Botsrun was cancelled; its rerun passed. - Not run:
pytest tests/python,npm test.
Appendix: non-blocking (1)
- Pre-existing, filed #365: unsupported
${var...}operators such as${x//a/_},${x^^}and${x:1:3}are silently dropped. Unrelated to this change; I ran into it while probing the matcher's other callers.
Description
casetreated a quoted pattern as a glob, socase abc in "a*")took thea*arm, and so did a quoted$xholding*. That also meant a value compared with itself, likecase "$f" in "$f"), didn't match when it contained[, so the wrong arm ran with no error.Now the quoted parts of a case pattern match literally and the unquoted parts still glob, the same way
[[ == ]]already handles its right-hand side. Both places that runcase(normal and inside a command substitution) get the fix.Related Issues
Fixes #327
Documentation PR
N/A
Type of Change
Bug fix
Testing
I added a differential case covering single and double quotes, quoted and unquoted variables, mixed patterns like
a"*", and the self-match with brackets. On main it failed, and with the change it passes along with the full test suite. I left out backslash-escaped patterns likea\*, which still glob because the backslash is dropped earlier during parsing. That needs its own fix.cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.