mirror of
https://github.com/sharkdp/fd.git
synced 2024-09-28 13:01:30 +02:00
Fix --glob behavior with empty pattern
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.
This commit is contained in:
parent
db6fc44d05
commit
b22285ffe4
@ -122,7 +122,7 @@ fn run() -> Result<ExitCode> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let pattern_regex = if matches.is_present("glob") {
|
let pattern_regex = if matches.is_present("glob") && pattern.len() > 0 {
|
||||||
let glob = GlobBuilder::new(pattern).literal_separator(true).build()?;
|
let glob = GlobBuilder::new(pattern).literal_separator(true).build()?;
|
||||||
glob.regex().to_owned()
|
glob.regex().to_owned()
|
||||||
} else if matches.is_present("fixed-strings") {
|
} else if matches.is_present("fixed-strings") {
|
||||||
|
@ -52,7 +52,7 @@ fn create_file_with_size<P: AsRef<Path>>(path: P, size_in_bytes: usize) {
|
|||||||
f.write_all(content.as_bytes()).unwrap();
|
f.write_all(content.as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Simple tests
|
/// Simple test
|
||||||
#[test]
|
#[test]
|
||||||
fn test_simple() {
|
fn test_simple() {
|
||||||
let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
|
let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
|
||||||
@ -70,20 +70,35 @@ fn test_simple() {
|
|||||||
one/two/three/d.foo
|
one/two/three/d.foo
|
||||||
one/two/three/directory_foo",
|
one/two/three/directory_foo",
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Test each pattern type with an empty pattern.
|
||||||
|
#[test]
|
||||||
|
fn test_empty_pattern() {
|
||||||
|
let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
|
||||||
|
let expected = "a.foo
|
||||||
|
e1 e2
|
||||||
|
one
|
||||||
|
one/b.foo
|
||||||
|
one/two
|
||||||
|
one/two/c.foo
|
||||||
|
one/two/C.Foo2
|
||||||
|
one/two/three
|
||||||
|
one/two/three/d.foo
|
||||||
|
one/two/three/directory_foo
|
||||||
|
symlink";
|
||||||
|
|
||||||
te.assert_output(
|
te.assert_output(
|
||||||
&[],
|
&["--regex"],
|
||||||
"a.foo
|
expected,
|
||||||
e1 e2
|
);
|
||||||
one
|
te.assert_output(
|
||||||
one/b.foo
|
&["--fixed-strings"],
|
||||||
one/two
|
expected,
|
||||||
one/two/c.foo
|
);
|
||||||
one/two/C.Foo2
|
te.assert_output(
|
||||||
one/two/three
|
&["--glob"],
|
||||||
one/two/three/d.foo
|
expected,
|
||||||
one/two/three/directory_foo
|
|
||||||
symlink",
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user