Skip to content

Slashes inside gitignore bracket expressions split the pattern incorrectly #177

Closed

Description

@parijat1222q

Reproduction

On current master (47ea6a5b02bc):

from pathspec import GitIgnoreSpec

spec = GitIgnoreSpec.from_lines(['[a/b].txt'], backend='simple')
print(spec.match_file('a.txt'))  # False
print(spec.match_file('b.txt'))  # False

Git ignores both files with that same rule. For example, in a fresh repository:

printf '[a/b].txt\n' > .gitignore
touch a.txt b.txt
git check-ignore --no-index a.txt b.txt
# a.txt
# b.txt

The slash is inside a bracket expression, so it must not split the expression into two path segments. Git still treats the raw slash as making this rule relative to the ignore file's directory: dir/a.txt must not match this rule. A bracket must never consume an actual path separator either.

Both gitignore pattern factories currently split the original pattern at every /, before translating brackets. This also affects negated brackets and directory-only rules containing such a bracket.

This is distinct from #163, which prevented brackets from matching path separators, and #170, which handled escaped separators between segments. I have a fix with tests for bracket-aware splitting, anchoring, separator exclusion and optional-backend compatibility. No production incident is claimed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions