diff options
author | Andrew Gallant <jamslam@gmail.com> | 2017-03-12 15:51:07 -0400 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2017-03-12 15:51:17 -0400 |
commit | 80e91a1f1d725eb8e331f3613a352edb8b13677b (patch) | |
tree | 981ef24eabd2545b82599e16a99b07808972cf4c /ignore/src | |
parent | d570f78144b8fb63d02382630d10d5db174d21ce (diff) |
Fix leading slash bug when used with `!`.
When writing paths like `!/foo` in gitignore files (or when using the
-g/--glob flag), the presence of `!` would prevent the gitignore builder
from noticing the leading slash, which causes absolute path matching to
fail.
Fixes #405
Diffstat (limited to 'ignore/src')
-rw-r--r-- | ignore/src/gitignore.rs | 5 | ||||
-rw-r--r-- | ignore/src/overrides.rs | 6 |
2 files changed, 10 insertions, 1 deletions
diff --git a/ignore/src/gitignore.rs b/ignore/src/gitignore.rs index 7e547c2c..4972dcd5 100644 --- a/ignore/src/gitignore.rs +++ b/ignore/src/gitignore.rs @@ -368,9 +368,10 @@ impl GitignoreBuilder { }; let mut literal_separator = false; let has_slash = line.chars().any(|c| c == '/'); - let is_absolute = line.chars().nth(0).unwrap() == '/'; + let mut is_absolute = false; if line.starts_with("\\!") || line.starts_with("\\#") { line = &line[1..]; + is_absolute = line.chars().nth(0) == Some('/'); } else { if line.starts_with("!") { glob.is_whitelist = true; @@ -383,6 +384,7 @@ impl GitignoreBuilder { // simply banning wildcards from matching /. literal_separator = true; line = &line[1..]; + is_absolute = true; } } // If it ends with a slash, then this should only match directories, @@ -570,6 +572,7 @@ mod tests { not_ignored!( ignot14, "./third_party/protobuf", "m4/ltoptions.m4", "./third_party/protobuf/csharp/src/packages/repositories.config"); + not_ignored!(ignot15, ROOT, "!/bar", "foo/bar"); fn bytes(s: &str) -> Vec<u8> { s.to_string().into_bytes() diff --git a/ignore/src/overrides.rs b/ignore/src/overrides.rs index c737b04e..faf05f31 100644 --- a/ignore/src/overrides.rs +++ b/ignore/src/overrides.rs @@ -214,4 +214,10 @@ mod tests { assert!(ov.matched("src/foo", false).is_ignore()); assert!(ov.matched("src/foo", true).is_none()); } + + #[test] + fn absolute_path() { + let ov = ov(&["!/bar"]); + assert!(ov.matched("./foo/bar", false).is_none()); + } } |