Skip to content

grep: treat empty-bound intervals {,} and \{,\} as {0,} - #250

Open
yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:grep-empty-interval-zero-or-more
Open

yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:grep-empty-interval-zero-or-more

Conversation

@yunusarda-sudo

Copy link
Copy Markdown
Contributor

GNU grep treats an interval with neither bound (\{,\} in BRE, {,} in ERE) as {0,} (zero or more). Oniguruma's SYNTAX_BEHAVIOR_ALLOW_INTERVAL_LOW_ABBREV only covers {,n} with an upper bound, so \{,\} failed in BRE and {,} was read literally in ERE.

This normalizes unescaped, out-of-bracket \{,\} (BRE) and {,} (ERE) to \{0,\} / {0,} before leading-operator stripping and regex compilation, leaving -F and -P untouched.

Fixes #203

Investigated and verified locally with cargo fmt --check, cargo clippy --all-targets -- -D warnings, and cargo test.

Rewrite unescaped, out-of-bracket `\{,\}` (BRE) and `{,}` (ERE) to `\{0,\}` / `{0,}` before compiling with Oniguruma, matching GNU grep.

Fixes uutils#203
@codspeed

codspeed Bot commented Nov 25, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

Warning

uutils has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed.

1 warning

⚠️ 3 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 10 untouched benchmarks
⏩ 17 skipped benchmarks1


Comparing yunusarda-sudo:grep-empty-interval-zero-or-more (2ae1e88) with main (b2fd25a)

Open in CodSpeed

Footnotes

  1. 17 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.26%. Comparing base (b2fd25a) to head (2ae1e88).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #250      +/-   ##
==========================================
+ Coverage   97.19%   97.26%   +0.06%     
==========================================
  Files           6        6              
  Lines        2248     2300      +52     
  Branches      243      247       +4     
==========================================
+ Hits         2185     2237      +52     
  Misses         63       63              
Flag Coverage Δ
macOS_latest 98.15% <100.00%> (+0.04%) ⬆️
ubuntu_latest 98.15% <100.00%> (+0.04%) ⬆️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lhecker lhecker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have 15 regex parsers now. I don't feel like we should have more. May as well just write a regex engine then.

@yunusarda-sudo

Copy link
Copy Markdown
Contributor Author

Fair. Oniguruma rejects {,} even with low-abbrev enabled ({,3} is fine), so there's no syntax flag for it. Happy for you to drop this one if it isn't worth another scanner.

@yunusarda-sudo

Copy link
Copy Markdown
Contributor Author

Fair point. Would you prefer these GNU syntax differences to be handled by translating the pattern in one place (or upstream in the regex crate), or is this class of edge cases not worth handling here? If the latter, I'm happy to close this one and the similar ones (#248, #251, #253, #256).

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.

grep - the interval {,} (\{,\} in BRE) is rejected or read literally; GNU reads it as {0,}

2 participants