Skip to content

Conversation

frendsick
Copy link
Contributor

@frendsick frendsick commented May 27, 2025

This PR fixes parsing and error reporting for the regex range quantifiers for expr. The \{ token is handled literally when used at the start of the regex or its subexpressions. The following closing braces \} are also handled literally until the next \{ that is not at the start of an expression.

Quote from #8009:

Normally, \{ begins a range quantifier like {n,m}. However, at the start of the regex or its subexpression (after \( or \|), there is no preceding item to which the quantifier can be applied. The expr command should handle \{ literally at the start of the regex or its subexpression.

Other changes:

  • Remove nonexistent error UnmatchedClosingBrace
    • The closing brace without a related opening brace is handled literally
  • Fix error message for too big range quantifier index
    • "Invalid content of {}" --> "Regular expression too big"
  • Simplify transpiling input regex pattern from BRE syntax to onig crate's Syntax::grep

fixes: #8009

frendsick added 6 commits May 27, 2025 03:56
Normally, `\{` begins a range quantifier like `{n,m}`, but at the start of
an expression, there is no preceding item to apply the quantifier to.
The closing brace without related opening brace is handled literally
@frendsick frendsick force-pushed the fix/expr-regex-range-start-of-expression branch from cbdf90e to 639310c Compare May 27, 2025 01:27
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@frendsick frendsick requested a review from cakebaker May 27, 2025 11:04
@frendsick frendsick force-pushed the fix/expr-regex-range-start-of-expression branch from d033375 to 07caa48 Compare May 27, 2025 11:06
@frendsick frendsick force-pushed the fix/expr-regex-range-start-of-expression branch from 14e5bd5 to ca6a10e Compare May 27, 2025 12:28
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@frendsick frendsick changed the title expr: Handle \{ literally at the start of a regex expression expr: Fix handling of regex range quantifiers May 27, 2025
@frendsick frendsick force-pushed the fix/expr-regex-range-start-of-expression branch from 120ab2e to ddd93dc Compare May 27, 2025 14:03
@frendsick frendsick force-pushed the fix/expr-regex-range-start-of-expression branch from ddd93dc to 4946922 Compare May 27, 2025 14:28
@frendsick frendsick requested a review from cakebaker May 27, 2025 14:59
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@cakebaker cakebaker merged commit 5fd4ab5 into uutils:main May 27, 2025
74 checks passed
@cakebaker
Copy link
Contributor

Good work, thanks!

@frendsick frendsick deleted the fix/expr-regex-range-start-of-expression branch June 6, 2025 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

expr: Handle \{ literally at the start of an expression or subexpression
2 participants