You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
find / locate - -regextype grep: . and [^...] never match a newline in the path #1046
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.rsmod tests:
#[test]fngrep_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'.
Activity
Make grep regex type match newlines in paths
Fix grep regex syntax so newlines match in paths
Make grep regex type match newlines in paths
Fix grep regex syntax so newlines match in paths
Make grep regex type match newlines in paths
Fix grep regex syntax so newlines match in paths