summaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
authorKento Okamoto <kentokamoto@protonmail.com>2023-10-13 22:49:21 -0700
committerAndrew Gallant <jamslam@gmail.com>2023-11-20 23:51:53 -0500
commit922bad2b92a564ac442368e9e2522f11d61f593f (patch)
treef455879cab66adac6a814ae1ea7a0b7dbc1ad7dc /crates
parent538ba956dc00b4317d0f40dc6324c31e9e1c40a9 (diff)
ignore: improve 'excludesFile' parsing
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
Diffstat (limited to 'crates')
-rw-r--r--crates/ignore/src/gitignore.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/crates/ignore/src/gitignore.rs b/crates/ignore/src/gitignore.rs
index da007298..0b667f26 100644
--- a/crates/ignore/src/gitignore.rs
+++ b/crates/ignore/src/gitignore.rs
@@ -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
@@ -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() {