Skip to content

Make grep regex type match newlines in paths - #1053

Open
Wooohaaa wants to merge 2 commits into
uutils:mainfrom
Wooohaaa:fix/grep-regex-newline
Open

Wooohaaa wants to merge 2 commits into
uutils:mainfrom
Wooohaaa:fix/grep-regex-newline

Conversation

@Wooohaaa

Copy link
Copy Markdown

Fixes #1046.

Oniguruma's grep syntax is line-oriented by default, so with -regextype grep, '.' and negated brackets never match a newline in a path. GNU's grep type does.

Enables REGEX_OPTION_MULTILINE (dot matches newline) and REGEX_OPTION_NEGATE_SINGLELINE (negated brackets match newline) for the Grep type in both find -regex and locate --regex. Adds an integration test with a newline-containing filename.

Note: cargo is unavailable locally, so build/tests could not be run here.

Ls::print unwrapped file_info.metadata(), so a file removed between the
directory read and -ls (or an ENAMETOOLONG/EACCES failure) aborted the
whole traversal with a panic, skipping remaining entries and pending
-exec batches.

Handle the error like GNU find: print one diagnostic, set exit code 1,
and continue. Add a regression test using -exec rm before -ls.

Fixes uutils#1044
Oniguruma's grep syntax is line-oriented by default, so with -regextype
grep, '.' and negated brackets never match a newline in a path. GNU's
grep type does. Enable REGEX_OPTION_MULTILINE (dot matches newline) and
REGEX_OPTION_NEGATE_SINGLELINE (negated brackets match newline) for the
Grep type in both find -regex and locate --regex.

Adds an integration test with a filename containing a newline.

Fixes uutils#1046
@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.07407% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.31%. Comparing base (3d12105) to head (b0bf646).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/find/matchers/ls.rs 54.54% 4 Missing and 1 partial ⚠️
src/locate/mod.rs 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1053      +/-   ##
==========================================
+ Coverage   92.29%   92.31%   +0.01%     
==========================================
  Files          38       38              
  Lines        8714     8727      +13     
  Branches      429      432       +3     
==========================================
+ Hits         8043     8056      +13     
+ Misses        532      531       -1     
- Partials      139      140       +1     

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

@pethapixels-create

Copy link
Copy Markdown
Contributor

Closing this PR — it combines two unrelated changes: (1) the ls.rs stat-failure fix which is already submitted cleanly as #1052, and (2) a grep regex newline change that doesn't have a clean upstream solution (onig grep syntax is line-oriented by design). Splitting into #1052 for the ls.rs fix. Sorry for the noise.

@codspeed

codspeed Bot commented Nov 24, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 15 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

✅ 20 untouched benchmarks


Comparing Wooohaaa:fix/grep-regex-newline (b0bf646) with main (b6e66fd)

Open in CodSpeed

@sylvestre

Copy link
Copy Markdown
Contributor

the ls.rs part is #1052, please send the grep regex fix alone, with tests for [^...] and locate

// clear SINGLELINE (so negated brackets also match newline).
if regex_type == RegexType::Grep {
options.insert(RegexOptions::REGEX_OPTION_MULTILINE);
options.insert(RegexOptions::REGEX_OPTION_NEGATE_SINGLELINE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

are you sure NEGATE_SINGLELINE makes [^...] match newline?
i think it only changes $, please add a test with [^/]* on the newline file

Comment thread src/locate/mod.rs
// SINGLELINE so negated brackets match newline too.
if ty == RegexType::Grep {
options.insert(RegexOptions::REGEX_OPTION_MULTILINE);
options.insert(RegexOptions::REGEX_OPTION_NEGATE_SINGLELINE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please add a locate test too
almost the same code as in regex.rs, could be shared, no?

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.

find / locate - -regextype grep: . and [^...] never match a newline in the path

3 participants