Repository navigation
Treat a reversed bracket range as a literal in gitignore patterns - #193
Open
shashank11yadav wants to merge 1 commit into
Open
shashank11yadav wants to merge 1 commit into
shashank11yadav wants to merge 1 commit into
Conversation
A pattern such as "[z-a]" crashed with a raw re.error when errors was "literal", which is the default for GitIgnoreBasicPattern. The bracket expression was only checked in "raise" mode. Check it in every mode and, outside "raise", treat the whole bracket expression as a literal, as is already done for an invalid POSIX class.
This branch has not been deployed
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.
Fixes #192
A gitignore pattern with a reversed bracket range, such as
[z-a], raised a rawre.errorin the default'literal'mode.GitIgnoreBasicPatternuses that mode by default, soPathSpec.from_lines('gitignore', ['[z-a]'])failed to build.The bracket expression was only checked with
re.compilewhenerrors='raise'. The check now runs in every mode. In'raise'mode the sameGitIgnorePatternErroris raised as before. In the other modes the whole bracket expression is treated as literal text, the same fallback already used for an invalid POSIX class.Test changes:
tests/test_03_gitignore_basic.py,test_c_2_invalid: this changes an existing maintainer assertion. The old block asserted that'[z-a]'and'a[z-a]'raisere.error("Theremodule fails to compile these"). The PR moves these two patterns into the literal list above it, with their expected regexes, and removes thatassertRaisesblock. It also removes there_PatternErrorimport, which is no longer used. The reason is that the crash is the bug this PR fixes.tests/test_08_gitignore_bracket_slash.py: newtest_reversed_rangechecksGitIgnoreBasicPatternandGitIgnoreSpecPatternin'literal','null'and'raise'modes, plus an end-to-endPathSpeccheck.Behaviour in literal mode:
[z-a]matches a file named[z-a]and does not matchz. Git's handling of reversed ranges is not part of these tests, and this PR does not change it, so the difference from Git for this line remains.Testing:
python3 -m unittest discover -t . -s tests/from the clone root, passes: 323 tests run, 957 skipped, OK.test_c_2_invalidboth error without the fix (re.PatternError: bad character range z-a) and pass with it. This was a local run. CI was not run.