Repository navigation
Reject a regular expression that ends in a lone backslash - #118634
Closed
alexey-milovidov wants to merge 1 commit into
Closed
alexey-milovidov wants to merge 1 commit into
alexey-milovidov wants to merge 1 commit into
Conversation
`match('abcd', 'abc\\')` returned `1`, and `match(s, '\\')` returned `1` for
every row. A trailing backslash is invalid in re2 (`trailing \`), but the
pattern analyzer consumed it at the end of the pattern and stopped, leaving the
pattern classified as a trivial literal - and everything trivial is answered by
a substring search, so re2, which would have rejected the pattern, never saw it.
The same pattern is rejected by `replaceRegexpAll`, by `multiMatchAny`, and by
`match` itself in any non-trivial spelling (`^abc\`, `ab(c)\`).
`analyzeImpl` now marks such a pattern non-trivial, so it is compiled and
reported as `CANNOT_COMPILE_REGEXP`, like every other invalid regular
expression. Escapes with a character after the backslash are unaffected.
`01866_split_by_regexp` asserted the old answer for
`splitByRegexp('\\', 'a\\b\\c')` - the whole string, unsplit - next to the same
assertion for the other invalid patterns (`+`, `?`, `(`, `[`), which already
expect `CANNOT_COMPILE_REGEXP`; it now expects that too.
Closes: #117853
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [65b4724] Summary: ❌
AI ReviewSummaryThis PR fixes the Final Verdict
LLVM Coverage ReportMeasured on commit 65b4724.
Changed lines: Changed C/C++ lines covered: 6/6 (100.00%) · Uncovered code |
Member
|
Duplicate of #118229 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: #117853
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A regular expression that ends in a lone backslash is now rejected as invalid by
match,extractAll,countMatchesandsplitByRegexp, instead of being answered as a search for the pattern without the backslash.Description
match('abcd', 'abc\\')returned1andmatch(s, '\\')returned1for every row. A trailing backslash is invalid in re2 (trailing \), but the pattern analyzer consumed it at the end of the pattern and stopped, leaving the pattern classified as a trivial literal - and everything trivial is answered by a substring search, so re2, which would have rejected the pattern, never saw it. The same pattern is rejected byreplaceRegexpAll, bymultiMatchAny, and bymatchitself in any non-trivial spelling (^abc\,ab(c)\).OptimizedRegularExpression::analyzeImplnow marks such a pattern non-trivial, so it is compiled and reported asCANNOT_COMPILE_REGEXP, like every other invalid regular expression. Escapes with a character after the backslash are unaffected.01866_split_by_regexpasserted the old answer forsplitByRegexp('\\', 'a\\b\\c')- the whole string, unsplit - next to the same assertion for the other invalid patterns (+,?,(,[), which already expectCANNOT_COMPILE_REGEXP; it now expects that too.Workflow [PR]
Sync PR [sync-upstream/pr/118634]