Skip to content

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

Backlog

Description

@sylvestre

With -regextype grep, find -regex / -iregex and locate --regex --regextype grep use
Oniguruma's stock grep syntax, which is line-oriented: . does not match \n, and
negated bracket expressions exclude \n. -regex has to match the whole path, so any path
with a newline in any component fails patterns such as .*\.php. GNU's grep regex type
matches these paths. uutils' own posix-basic and posix-extended types already match them
correctly.

Reproduction

$ mkdir up && touch up/plain.php up/$'new\nline.php'

Rust (incorrect)

$ ./target/release/find up -regextype grep -regex '.*\.php' | od -c
0000000   u   p   /   p   l   a   i   n   .   p   h   p  \n
# Exit code: 0     (the newline-named file is missing)
$ ./target/release/find up -regextype posix-basic -regex '.*\.php' -printf .; echo
..                 # posix-basic finds both

GNU (correct)

$ LC_ALL=C /usr/bin/find up -regextype grep -regex '.*\.php' | od -c
0000000   u   p   /   n   e   w  \n   l   i   n   e   .   p   h   p  \n
0000020   u   p   /   p   l   a   i   n   .   p   h   p  \n
# Exit code: 0

locate has the same problem. With a database built by updatedb --localpaths=$PWD/up:

$ ./target/release/locate -d up.db --regex --regextype grep 'new.line'   # no output, exit 1
$ /usr/bin/locate        -d up.db --regex --regextype grep 'new.line'   # prints the entry, exit 0

Test

In src/find/matchers/regex.rs mod tests:

#[test]
fn grep_type_matches_newline_in_path() {
    let m = RegexMatcher::new(RegexType::Grep, r".*\.php", false).unwrap();
    let entry = /* build a WalkEntry for "up/new\nline.php" with the existing test helpers */;
    assert!(m.matches(&entry, &mut deps.new_matcher_io()));
}

or as an integration test in tests/test_find.rs (#[cfg(unix)], since the file name has a
\n) that creates the file and checks that it appears in the stdout of
-regextype grep -regex '.*\.php'.

Reported by Anthropic's OSS Scanner.

Activity

  1. added 2 commits that reference this issue on Nov 25, 2026
    3153f18
    fb3980f
  2. added 4 commits that reference this issue on Nov 25, 2026
    c1e6cb3
    f5aebd8
    3356d92
    bd2c9e6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggnu-compatgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions