Skip to content

Commit

Permalink
ignore: improve 'excludesFile' parsing
Browse files Browse the repository at this point in the history
This permits the value to be surrounded in double quotes. It's still not
perfect, but probably better than it was. Getting this to be more
correct will likely require writing (or using) a real parser, which I'm
not particularly incliend to do at present.

Fixes #2392, Closes #2629
  • Loading branch information
Kento Okamoto authored and BurntSushi committed Oct 15, 2023
1 parent d8b1823 commit 004747b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Bug fixes:
Fix gitignore parsing bug where a trailing `\/` resulted in an error.
* [BUG #2243](https://github.com/BurntSushi/ripgrep/issues/2243):
Fix `--sort` flag for values other than `path`.
* [BUG #2392](https://github.com/BurntSushi/ripgrep/issues/2392):
Improve global git config parsing of the `excludesFile` field.
* [BUG #2480](https://github.com/BurntSushi/ripgrep/issues/2480):
Fix bug when using inline regex flags with `-e/--regexp`.
* [BUG #2523](https://github.com/BurntSushi/ripgrep/issues/2523):
Expand Down
18 changes: 17 additions & 1 deletion crates/ignore/src/gitignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ fn parse_excludes_file(data: &[u8]) -> Option<PathBuf> {
Regex::builder()
.configure(Regex::config().utf8_empty(false))
.syntax(syntax::Config::new().utf8(false))
.build(r"(?im-u)^\s*excludesfile\s*=\s*(\S+)\s*$")
.build(r#"(?im-u)^\s*excludesfile\s*=\s*"?\s*(\S+?)\s*"?\s*$"#)
.unwrap()
});
// We don't care about amortizing allocs here I think. This should only
Expand Down Expand Up @@ -772,6 +772,22 @@ mod tests {
assert!(super::parse_excludes_file(&data).is_none());
}

#[test]
fn parse_excludes_file4() {
let data = bytes("[core]\nexcludesFile = \"~/foo/bar\"");
let got = super::parse_excludes_file(&data);
assert_eq!(
path_string(got.unwrap()),
super::expand_tilde("~/foo/bar")
);
}

#[test]
fn parse_excludes_file5() {
let data = bytes("[core]\nexcludesFile = \" \"~/foo/bar \" \"");
assert!(super::parse_excludes_file(&data).is_none());
}

// See: https://github.com/BurntSushi/ripgrep/issues/106
#[test]
fn regression_106() {
Expand Down

0 comments on commit 004747b

Please sign in to comment.