From 20ccd441f2d6000100bbbbade37aeca492d55ee0 Mon Sep 17 00:00:00 2001 From: Tom Jackson Date: Mon, 26 Sep 2016 09:34:32 -0700 Subject: [PATCH 1/2] Allow (and ignore) whitespace-only lines in .gitignore files Git considers these to be blank lines. --- src/gitignore.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gitignore.rs b/src/gitignore.rs index e05dc58..c4f46fa 100644 --- a/src/gitignore.rs +++ b/src/gitignore.rs @@ -283,12 +283,15 @@ impl GitignoreBuilder { from: P, mut line: &str, ) -> Result<(), Error> { - if line.is_empty() || line.starts_with("#") { + if line.starts_with("#") { return Ok(()); } if !line.ends_with("\\ ") { line = line.trim_right(); } + if line.is_empty() { + return Ok(()); + } let mut pat = Pattern { from: from.as_ref().to_path_buf(), original: line.to_string(), From f27aa3ff6fcff9adfa312d8d404254419f90c029 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Mon, 26 Sep 2016 18:55:26 -0400 Subject: [PATCH 2/2] Add regression test. Fixes #106. --- src/gitignore.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/gitignore.rs b/src/gitignore.rs index c4f46fa..bfc8384 100644 --- a/src/gitignore.rs +++ b/src/gitignore.rs @@ -429,4 +429,10 @@ mod tests { not_ignored!(ignot11, ROOT, "#foo", "#foo"); not_ignored!(ignot12, ROOT, "\n\n\n", "foo"); not_ignored!(ignot13, ROOT, "foo/**", "foo", true); + + // See: https://github.com/BurntSushi/ripgrep/issues/106 + #[test] + fn regression_106() { + Gitignore::from_str("/", " ").unwrap(); + } }