Fix escape() not escaping backslash characters#106
Merged
Conversation
The escape() method escapes special gitignore characters so that a
literal filename can be used as a pattern. However, it only escapes
[]-f pr_body_1.md && git checkout master && git checkout -b fix/escape-backslash master#? and misses backslash, which is the escape character in
gitignore patterns.
Without this fix, escape('foo\\bar') returns 'foo\\bar' unchanged.
When this is then parsed as a gitignore pattern, the backslash is
consumed as an escape sequence (escaping 'b'), so the resulting
pattern matches 'foobar' instead of the intended 'foo\\bar'.
Add backslash to the set of characters that get escaped.
Owner
|
Thanks for finding and fixing this bug. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
escape()method is meant to escape special characters in a filename so it can be safely used as a gitignore pattern. Currently it escapes[]!*#?but misses backslash (\), which is the escape character in gitignore patterns.This means
escape()doesn't produce a round-trippable result for filenames containing backslashes:The fix adds
\\to the set of escaped characters, soescape('foo\\bar')correctly produces'foo\\\\bar', which the parser then interprets as a literal backslash.