Skip to content

grep: reject chained range operators like [a-c-e] in bracket expressions - #248

Open
yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:grep-reject-double-range-op
Open

yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:grep-reject-double-range-op

Conversation

@yunusarda-sudo

Copy link
Copy Markdown
Contributor

A bracket expression cannot chain range operators: in [a-c-e] the second - has a range as its left endpoint, and GNU grep rejects it with Invalid range end (exit 2) in both basic and extended mode.

Previously, grep -E enabled SYNTAX_BEHAVIOR_ALLOW_DOUBLE_RANGE_OP_IN_CC via Syntax::gnu_regex() and accepted it as [a-c], -, e. In basic mode, Oniguruma rejected it with an untranslated internal error message.

This PR disables SYNTAX_BEHAVIOR_ALLOW_DOUBLE_RANGE_OP_IN_CC under -E and maps ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS to "Invalid range end", matching GNU grep behavior in both modes.

Fixes #163

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.22%. Comparing base (bf6f25e) to head (28cde0d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #248   +/-   ##
=======================================
  Coverage   97.22%   97.22%           
=======================================
  Files           6        6           
  Lines        2270     2271    +1     
  Branches      245      245           
=======================================
+ Hits         2207     2208    +1     
  Misses         63       63           
Flag Coverage Δ
macOS_latest 98.13% <100.00%> (+<0.01%) ⬆️
ubuntu_latest 98.13% <100.00%> (+<0.01%) ⬆️
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.

@codspeed

codspeed Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

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-reject-double-range-op (28cde0d) with main (bf6f25e)

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. ↩

@yunusarda-sudo
yunusarda-sudo force-pushed the grep-reject-double-range-op branch from 98f4de8 to 471cbb6 Compare November 25, 2026 16:11
@yunusarda-sudo

Copy link
Copy Markdown
Contributor Author

Cygwin failure is unrelated: color_on_a_terminal_needs_option_and_term_not_dumb is flaky there (same failures on main, https://github.com/uutils/grep/actions/runs/45587825191).

GNU grep rejects bracket expressions with chained ranges like [a-c-e] with "Invalid range end" (exit 2) in both basic and extended mode. Disable ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC in extended mode and translate ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS into "Invalid range end".

Fixes uutils#163

Signed-off-by: Yunus Arda Güney <[email protected]>
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 - -E accepts a second range operator like [a-c-e] that GNU rejects

1 participant