From 4b5e789a2ae854d234cd8fd3a87380a0f99dc584 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sat, 24 Sep 2016 20:56:24 -0400 Subject: [PATCH] Strip trailing whitespace in gitignore patterns. Fixes #38. --- src/gitignore.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gitignore.rs b/src/gitignore.rs index 3341e6db..4d90be82 100644 --- a/src/gitignore.rs +++ b/src/gitignore.rs @@ -279,6 +279,9 @@ impl GitignoreBuilder { if line.is_empty() || line.starts_with("#") { return Ok(()); } + if !line.ends_with("\\ ") { + line = line.trim_right(); + } let mut pat = Pattern { from: from.as_ref().to_path_buf(), original: line.to_string(), @@ -401,6 +404,7 @@ mod tests { ignored!(ig27, ROOT, "foo/", "xyz/foo", true); ignored!(ig28, ROOT, "src/*.rs", "src/grep/src/main.rs"); ignored!(ig29, "./src", "/llvm/", "./src/llvm", true); + ignored!(ig30, ROOT, "node_modules/ ", "node_modules", true); not_ignored!(ignot1, ROOT, "amonths", "months"); not_ignored!(ignot2, ROOT, "monthsa", "months");