Repository navigation
grep: read an unmatched ) in -E as a literal - #150
jayhemnani9910 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
| (")", "a)\n(a)\n)\n"), | ||
| ("a)", "a)\n(a)\n"), | ||
| ("(a))", "a)\n(a)\n"), | ||
| ("b|)", "a)\n(a)\n)\nb\n"), |
There was a problem hiding this comment.
This seems a bit excessive. Are we unit testing the regex crate? :D
There was a problem hiding this comment.
Fair, cut it down to one case.
GNU grep -E treats a closing parenthesis with no open group as an ordinary character, so `grep -E 'a)'` matches "a)". We rejected the pattern with "unmatched close parenthesis". Basic regexps keep rejecting an unmatched \).
d06bc81 to
d5f0828
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
GNU grep -E takes a
)that closes no group as an ordinary character. Here the pattern is rejected:Same for
),(a)),b|),^),)*and so on. Oniguruma has a syntax flag for exactly this (ALLOW_UNMATCHED_CLOSE_SUBEXP, on in its own POSIX extended syntax), so the fix turns it on for-Eonly. In a basic regexp an unmatched\)is still an error, as in GNU;)there was already a literal.New test
ere_unmatched_close_paren_is_literal(fails on main).cargo test: test_grep 104 pass (103 on main), clippy and fmt clean. Against GNU grep 3.12, 33-Epatterns with unmatched, nested, escaped, bracketed and repeated parentheses give the same output and exit status, and the BRE cases (a\),\(a\)\),),\)) give the same exit status.