Skip to content

[bug] [[ string =~ ^(a|b)$ ]] with unquoted parenthesized regex aborts the parse: 'unexpected end of file from (' — pbb is_hex_color section dies #322

Closed

Description

@caomengxuan666

Found by ecosweep3 lane (pure-bash-bible corpus, section 003; carrier release build of 6106961). New construct instance of the over-strict family (#222), not covered by its listed shapes.

Reproducer (target/probe-out/p2.sh)

if [[ "#FFFFFF" =~ ^(#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3}))$ ]]; then
    echo "match:${BASH_REMATCH[1]}"
else
    echo "nomatch"
fi
  • GNU bash 5.3.0: match:#FFFFFF, rc=0
  • rubash: syntax error: unexpected end of file from ( command on line 2, rc=2

The unquoted regex word containing ( is lexed as a command-substitution opener. Quoting the regex (=~ $re with re variable, or quoted) is not affected — the pbb regex() helper (variable regex) passes.

GNU anchor

parse.y cond.c word after =~ is taken verbatim to EOL as the regex (see parse.y cond_regexp handling in parse.y:3688 region / bash MANUAL: within [[, the characters after =~ up to the closing ]] form the pattern; parens are not tokenized). If the C anchor line needs re-verification, grep cond_regexp in parse.y.

Impact

pbb 'Use regex on a string' section (is_hex_color) unparseable end-to-end; any script using inline unquoted parenthesized regexes in if/else bodies hits rc=2.

Activity

  1. added
    bug
    gnu-baseline
    on Sep 29, 2026
  2. caomengxuan666 commented on Sep 29, 2026

    @caomengxuan666
    MemberAuthor

    C anchor verified: parse.y:5439-5462 #ifdef COND_REGEXP block in read_token_word() — after =~ the parser keeps reading the regex word with COND_REGEXP handling so ( inside it is not a comsub opener. (Corrects the issue body's tentative anchor.)

  3. caomengxuan666 commented on Sep 29, 2026

    @caomengxuan666
    MemberAuthor

    pbbfix lane progress: scanner-level fix committed (wt14/pbbfix 99344ca0) — PST_REGEXP port into LexerParseState; [[ $v =~ ^(#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3}))$ ]] with variable/unquoted LHS now parses and matches byte-identical to GNU 5.3.0 (pbb is_hex_color section end-to-end green). Remaining: QUOTED-literal-LHS form ([[ "#FFFFFF" =~ ^(#?...)$ ]]) is blocked by a phantom-unterminated-( false positive in the completeness oracle (lexer/continuation.rs, captain-exclusive file) — validated proposed diff at target/issue-suites/results/pbbfix/issue322-continuation-proposed.diff handed to the captain for apply (quote-completion counts as word material for at_command, both one-shot and incremental copies; randomized consistency test green).

  4. added 2 commits that reference this issue on Sep 29, 2026
  5. caomengxuan666 commented on Sep 29, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by wt14/pbbfix (00df0f6, master): the tokenizer ate token-initial # inside the =~ RHS word as a comment. PST_CONDCMD/PST_REGEXP reader states ported into LexerParseState (GNU: parse.y:5169 sets PST_REGEXP, :5443-5461 the whole-word group swallow). Variable-LHS full regex + pbb 003 byte-identical; word-initial # stays a comment (GNU rc=2 preserved). ONE RESIDUE (continuation.rs is captain-exclusive): quoted-literal LHS ([[ "#FFFFFF" =~ ^(#?...) ]]) hits a phantom paren in the at_command tracking - the lane left a verified proposed diff at target/issue-suites/results/pbbfix/issue322-continuation-proposed.diff (one-shot and incremental forms, random-consistency tested),移交 captain per protocol.

  6. caomengxuan666 commented on Sep 29, 2026

    @caomengxuan666
    MemberAuthor

    Captain applied the lane's proposed continuation.rs patch (master 1237459): completed quote spans are word material for the at_command tracker in BOTH the one-shot close-char scan and the incremental residual advance (read_token returns one WORD token for a quoted span, parse.y:5305). Verified: the quoted-LHS form now MATCH-OK (was: syntax error unexpected EOF from '('), variable-LHS and word-initial-# semantics unchanged, 545 lib / 27 regression green.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions