1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-11-23 21:54:45 +02:00

globset: fix bug where trailing . in file name was incorrectly handled

I'm not sure why I did this, but I think I was trying to imitate the
contract of [`std::path::Path::file_name`]:

> Returns None if the path terminates in `..`.

But the status quo clearly did not implement this. And as a result, if
you have a glob that ends in a `.`, it was instead treated as the empty
string (which only matches the empty string).

We fix this by implementing the semantic from the standard library
correctly.

Fixes #2990

[`std::path::Path::file_name`]: https://doc.rust-lang.org/std/path/struct.Path.html#method.file_name
This commit is contained in:
Andrew Gallant
2025-08-17 17:18:27 -04:00
parent ba23ced817
commit 4df1298127
3 changed files with 27 additions and 5 deletions

View File

@@ -1461,3 +1461,19 @@ rgtest!(r2944_incorrect_bytes_searched, |dir: Dir, mut cmd: TestCommand| {
let got = cmd.args(&["--stats", "-m2", "foo", "."]).stdout();
assert!(got.contains("10 bytes searched\n"));
});
// See: https://github.com/BurntSushi/ripgrep/issues/2990
#[cfg(unix)]
rgtest!(r2990_trip_over_trailing_dot, |dir: Dir, _cmd: TestCommand| {
dir.create_dir("asdf");
dir.create_dir("asdf.");
dir.create("asdf/foo", "");
dir.create("asdf./foo", "");
let got = dir.command().args(&["--files", "-g", "!asdf/"]).stdout();
eqnice!("asdf./foo\n", got);
// This used to ignore the glob given and included `asdf./foo` in output.
let got = dir.command().args(&["--files", "-g", "!asdf./"]).stdout();
eqnice!("asdf/foo\n", got);
});