fix: silently discard unclosed bracket expressions#104
Open
ArmaanjeetSandhu wants to merge 1 commit intocpburnz:masterfrom
Open
fix: silently discard unclosed bracket expressions#104ArmaanjeetSandhu wants to merge 1 commit intocpburnz:masterfrom
ArmaanjeetSandhu wants to merge 1 commit intocpburnz:masterfrom
Conversation
Git silently discards gitignore patterns with unclosed bracket expressions (e.g., '[' or '[!]'), treating them as null-operations. Files with those literal names are tracked, not ignored. pathspec previously treated unclosed brackets as literal characters, creating regex patterns that would incorrectly match and ignore files with those names. This commit adds validation to detect unclosed bracket expressions and return (None, None) to indicate a null-operation pattern, matching Git's behavior exactly.
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.
Summary
Fixes #93 by making pathspec match Git's behavior for invalid gitignore patterns with unclosed bracket expressions.
Problem
Git silently discards patterns like
[and[!](unclosed brackets), treating them as null-operations. Files with those literal names are tracked.pathspec previously treated these as literal characters, creating regex patterns that would incorrectly ignore files named
[or[!].Solution
Added validation to detect unclosed bracket expressions and return
(None, None)(null-operation) instead of creating invalid regex patterns.Changes:
__has_unclosed_bracket()helper method to bothGitIgnoreBasicPatternandGitIgnoreSpecPatternpattern_to_regex()to check for unclosed brackets before processingVerification
Tested against
git check-ignoreto confirm identical behavior:With this fix, pathspec now produces the same result.
Test results:
[→ files named[are tracked ✓[!]→ files named[!]are tracked ✓[abc]still work correctly ✓Related
This completes the fixes mentioned in issue #93. The other issues mentioned (foo**/bar and leading whitespace) were already fixed in v1.0.0.