Skip to content

[bug] case pattern from expansion: quote chars in the result are wrongly treated as pattern quoting (glob killed) #2428

Closed

Description

@caomengxuan666

Summary

A case pattern that arrives via parameter expansion is mis-quoted when the expansion result contains quote characters: rubash reads quote spans in the result as pattern quoting, but GNU treats expansion results as carrying no quoting — glob characters inside them stay live.

Found en route to #2421 (PR #2427). Separate mechanism from #2421, present identically on master 42121884 and on the #2427 branch — not a regression.

Repro (self-contained)

p='"*"'
case '"xb"' in $p) echo "var-pattern: MATCH";; *) echo "var-pattern: nomatch";; esac
case '"*"'  in $p) echo "var-pattern-star: MATCH";; *) echo "var-pattern-star: nomatch";; esac
q='a"b'
case 'a"b' in $q) echo "var-quote-mid: MATCH";; *) echo "var-quote-mid: nomatch";; esac

Expected (GNU bash 5.3.20, verified)

var-pattern: MATCH
var-pattern-star: MATCH
var-quote-mid: MATCH

Actual (rubash master)

var-pattern: nomatch
var-pattern-star: nomatch
var-quote-mid: MATCH

Root area

decode_parameter_pattern_quotes in the case-pattern preparation path applies source-level quote semantics to the expansion result. Per GNU, quoting is a read-time property of the pattern word (parse.y read_token_word / CTLESC marking); text produced by expansion has no quoting attached, so */?/[...] in it are live pattern operators and " is an ordinary character. The fix belongs to the pattern-prep mechanism (distinguish source-quoted spans from expansion-result text), not to per-shape special cases.

Fix destination

Pattern family, later wave (post-1.5.0-gate, land-if-clean). PR #2427 does not cover this. Regression seed: the repro above, expectations per GNU.

Regression seed

Activity

  1. added
    bug
    area:glob
    on Nov 1, 2026
  2. added a commit that references this issue on Nov 1, 2026
  3. caomengxuan666 commented on Nov 1, 2026

    @caomengxuan666
    MemberAuthor

    PR #2451 (merged, master d44dce1). Case patterns decoded from expansion results now use the expansion-result quote mode (quoting is read-time only — parse.y CTLESC; execute_cmd.c:3733-3736), so glob characters arriving from values stay literal. My verification: issue2428 pins 4/4 + the #2421 guard target 6/6 green (scrubbed-fd harness).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area:globbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions