diff options
author | Brian Malehorn <bmalehorn@gmail.com> | 2018-02-22 23:15:16 -0800 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2018-03-10 09:30:55 -0500 |
commit | 91d0756f62790356012d692a7b340df92b54beac (patch) | |
tree | ea9cfa47cd6658bb27bd7ebed1b0b44b60a9f99e /ignore | |
parent | 54256515b49595a2ac4c2b218e4ddbb5a4920d9b (diff) |
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
Diffstat (limited to 'ignore')
-rw-r--r-- | ignore/src/gitignore.rs | 5 |
1 files changed, 5 insertions, 0 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"); |