Skip to content
Myr

Fix --glob behavior with empty pattern

Before adoption: this commit came in with the history the project adopted, so no landing records it.

With an empty pattern, --glob results in no matches. This does not align with the behavior of --fixed-strings or --regex. Update the initialization code to handle globs with empty patterns.

authored by Seamus Connor · committed by David Peter · parent db6fc44 · Browse files · 2 files+29 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+29 added−14 removed

  • tests:+28 added−13 removed
  • other:+1 added−1 removed

2 files+29 added−14 removed

modified:src/main.rs+1 added-1 removed
120 unmodified lines
121 sep = std::path::MAIN_SEPARATOR,122 ));123 }124125 let pattern_regex = if matches.is_present("glob") {125 let pattern_regex = if matches.is_present("glob") && pattern.len() > 0 {126 let glob = GlobBuilder::new(pattern).literal_separator(true).build()?;127 glob.regex().to_owned()128 } else if matches.is_present("fixed-strings") {129 // Treat pattern as literal string if '--fixed-strings' is used
271 unmodified lines
modified:tests/tests.rs+28 added-13 removed
50 unmodified lines
51 let mut f = fs::File::create::<P>(path).unwrap();52 f.write_all(content.as_bytes()).unwrap();53}5455/// Simple tests55/// Simple test56#[test]57fn test_simple() {58 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);59
9 unmodified lines
69 one/two/C.Foo270 one/two/three/d.foo71 one/two/three/directory_foo",72 );73}7475/// Test each pattern type with an empty pattern.76#[test]77fn test_empty_pattern() {78 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);79 let expected = "a.foo80 e1 e281 one82 one/b.foo83 one/two84 one/two/c.foo85 one/two/C.Foo286 one/two/three87 one/two/three/d.foo88 one/two/three/directory_foo89 symlink";9091 te.assert_output(75 &[],76 "a.foo77 e1 e278 one79 one/b.foo80 one/two81 one/two/c.foo82 one/two/C.Foo283 one/two/three84 one/two/three/d.foo85 one/two/three/directory_foo86 symlink",92 &["--regex"],93 expected,94 );95 te.assert_output(96 &["--fixed-strings"],97 expected,98 );99 te.assert_output(100 &["--glob"],101 expected,102 );103}104105/// Test multiple directory searches106#[test]
1477 unmodified lines