Skip to content

grep: check -w and -x against full match start before \K - #252

Open
yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:grep-perl-keep-word-line-regexp
Open

yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:grep-perl-keep-word-line-regexp

Conversation

@yunusarda-sudo

Copy link
Copy Markdown
Contributor

In -P mode, \K resets the start of the reported match in region.pos(0), while OnigRegex::search returns the actual start of the full match.

Previously, CompiledPattern::search_leftmost discarded the return value of search and used region.pos(0) for everything, causing -w and -x to test only the portion after \K (and longest_end_at to anchor at the trimmed start).

This introduces MatchSpan { match_start, report_start, end } so -w / -x and longest_end_at use match_start, while -o / highlighting continue to use report_start..end.

Fixes #181

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

Keep the regex match start returned by Oniguruma search separate from region group 0's start (which \K resets) so -w and -x validate the full match while -o and highlighting still use the reported span after \K.

Fixes uutils#181
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.16%. Comparing base (b2fd25a) to head (cbe026a).

Files with missing lines Patch % Lines
src/matcher.rs 96.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #252      +/-   ##
==========================================
- Coverage   97.19%   97.16%   -0.04%     
==========================================
  Files           6        6              
  Lines        2248     2254       +6     
  Branches      243      244       +1     
==========================================
+ Hits         2185     2190       +5     
- Misses         63       64       +1     
Flag Coverage Δ
macOS_latest 98.07% <96.66%> (-0.04%) ⬇️
ubuntu_latest 98.07% <96.66%> (-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.

@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

⚠️ 2 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-perl-keep-word-line-regexp (cbe026a) 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. ↩

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 - -w/-x test only the part of a -P match after \K

1 participant