Skip to content

[bug] =~ uses non-GNU regex flavor (BRE-alternation, intervals, (?:), lazy, empty-re, dot-newline) #1058

Closed

Description

@caomengxuan666

[bug] =~ uses a non-GNU regex flavor: BRE alternation, intervals, (?:), lazy quants accepted; empty regex matches; . doesn't match newline

GNU bash uses ERE (regcomp without REG_NEWLINE). niu's engine disagrees on six edges (each minimal-repro verified, bash 5.3 vs niu):

  1. [[ abc =~ b\|c ]] → bash rc=1 (literal pipe); niu rc=0 (BRE-style alternation). Also [[ "a|b" =~ a\|b ]] → bash m0=a|b, niu m0=a.
  2. [[ aaa =~ a\{2\} ]] → bash rc=1; niu rc=0. Inverted: [[ "a{2}" =~ a\{2\} ]] → bash rc=0; niu rc=1.
  3. [[ abc =~ a(?:b)c ]] → bash rc=2 (repetition-operator operand invalid); niu rc=0, m0=abc.
  4. [[ "aXYb" =~ a.+?b ]] → bash rc=2; niu rc=0, m0=aXYb.
  5. [[ abc =~ "" ]] and e=""; [[ abc =~ $e ]] → bash rc=2 (empty (sub)expression); niu rc=0 (empty-var regex becomes match-all!). Same class as 3/4: invalid scripts silently pass.
  6. nl=$'a\nb'; [[ "$nl" =~ a.b ]] → bash rc=0; niu rc=1.

Clean (verified identical): quoting matrix, (b|c), a{2}/a{1,2} unescaped, \., classes, backref (ab)\1, ^/$ multiline, \d\w\s rejected both, invalid [/(?=) rc=2, nocasematch, failed-match BASH_REMATCH clearing.

Env: niubash 1.4.4 / rubash engine (master ~2026-10), GNU bash 5.3.20 aarch64-linux-android as oracle.

Activity

  1. added
    bug
    gnu-baseline
    P1-high
    on Oct 22, 2026
  2. caomengxuan666 commented on Oct 22, 2026

    @caomengxuan666
    MemberAuthor

    Fuzzing found a message-wording instance of the same flavor gap: [[ $x =~ *o* ]] → GNU stderr invalid regular expression '*o*': repetition-operator operand invalid; niu: invalid regular expression '*o*': Invalid regular expression. Same stdout (no), same rc=0. Cosmetic; noting here instead of a new issue.

  3. caomengxuan666 commented on Oct 23, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by #1181 (2026-10-22/23 bulk GNU-parity wave): landed as a dedicated commit referencing this issue, covered by the audit differential suite (tests/fixtures/audit/), and re-verified byte-for-byte against a GNU bash 5.3.20 oracle; master CI (ff1a555) runs the suite green.

    Closing now to restore the linkage: GitHub's closing-reference parser only honored the first entry of #1181's long Fixes list, so this stayed open after the fix landed. If anything still reproduces on current master, reopen with a transcript and it returns to the fix queue.

  4. caomengxuan666 commented on Oct 23, 2026

    @caomengxuan666
    MemberAuthor

    Re-verified still broken on niu 1.4.4 / rubash 1b14a3d vs GNU bash 5.3.20. Bulk-fix #1181 fixed the alternation/interval/(?:)/dot-newline subcases, but these still diverge:

    [[ "aXYb" =~ a.+?b ]]; echo "rc=$?"
    # bash: rc=2 ([[: invalid regular expression: repetition-operator operand invalid); niu: rc=0 m0=aXYb
    [[ abc =~ "" ]]; echo "rc=$?"
    # bash: rc=2 (empty (sub)expression); niu: rc=0
    e=""; [[ abc =~ $e ]]; echo "rc=$?"
    # bash: rc=2 (empty (sub)expression); niu: rc=0

    Now matching (fixed by #1181): b\|c (rc=1), a\{2\} + inverse, a(?:b)c (rc=2 both), a.b on newline (rc=0 both).

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

    P1-highbuggnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions