From 91d0756f62790356012d692a7b340df92b54beac Mon Sep 17 00:00:00 2001 From: Brian Malehorn Date: Thu, 22 Feb 2018 23:15:16 -0800 Subject: [PATCH] ignore: support backslash escaping Use the new `Globset::backslash_escape` knob to conform to git behavior: `\` will escape the following character. For example, the pattern `\*` will match a file literally named `*`. Also tweak a test in ripgrep that was relying on this incorrect behavior. Closes #526, Closes #811 --- ignore/src/gitignore.rs | 5 +++++ tests/tests.rs | 6 +----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ignore/src/gitignore.rs b/ignore/src/gitignore.rs index 7e7233d6..83392e1e 100644 --- a/ignore/src/gitignore.rs +++ b/ignore/src/gitignore.rs @@ -477,6 +477,7 @@ impl GitignoreBuilder { GlobBuilder::new(&glob.actual) .literal_separator(literal_separator) .case_insensitive(self.case_insensitive) + .backslash_escape(true) .build() .map_err(|err| { Error::Glob { @@ -635,6 +636,10 @@ mod tests { ignored!(ig35, "./.", ".a/b", ".a/b"); ignored!(ig36, "././", ".a/b", ".a/b"); ignored!(ig37, "././.", ".a/b", ".a/b"); + ignored!(ig38, ROOT, "\\[", "["); + ignored!(ig39, ROOT, "\\?", "?"); + ignored!(ig40, ROOT, "\\*", "*"); + ignored!(ig41, ROOT, "\\a", "a"); not_ignored!(ignot1, ROOT, "amonths", "months"); not_ignored!(ignot2, ROOT, "monthsa", "months"); diff --git a/tests/tests.rs b/tests/tests.rs index 34bf08e4..6becfe0f 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -800,11 +800,7 @@ clean!(regression_25, "test", ".", |wd: WorkDir, mut cmd: Command| { // See: https://github.com/BurntSushi/ripgrep/issues/30 clean!(regression_30, "test", ".", |wd: WorkDir, mut cmd: Command| { - if cfg!(windows) { - wd.create(".gitignore", "vendor/**\n!vendor\\manifest"); - } else { - wd.create(".gitignore", "vendor/**\n!vendor/manifest"); - } + wd.create(".gitignore", "vendor/**\n!vendor/manifest"); wd.create_dir("vendor"); wd.create("vendor/manifest", "test");