Skip to content

GitIgnoreSpec misses anchored rules for redundant interior path separators #176

Open

Description

@agammann

Summary

GitIgnoreSpec misses an anchored ignore rule when a relative path contains a doubled slash or an interior ./ component. Git matches all three spellings of the same file. This can make a caller report an ignored file as unignored when its relative path was assembled by concatenation.

Tested with pathspec 1.1.1 at current master 47ea6a5b02bc, Python 3.14.8 and Git 2.55.0 on Windows.

Reproduction

from pathspec import GitIgnoreSpec

spec = GitIgnoreSpec.from_lines(['/data/private.txt'])
for path in ('data/private.txt', 'data//private.txt', 'data/./private.txt'):
    print(path, spec.match_file(path))
data/private.txt True
data//private.txt False
data/./private.txt False

For comparison, in a Git repository with an existing data/private.txt and .gitignore containing /data/private.txt, git check-ignore -v --no-index data/private.txt data//private.txt data/./private.txt reports that same rule for all three arguments. The alternate spellings also resolve to the same file on disk.

Expected

All three paths match the anchored ignore rule, as they do in Git.

Cause and related work

normalize_file() normalizes separator characters and a leading ./, but retains redundant interior separators and ./ components. Related PR #173 addresses repeated leading ./ prefixes; I checked its current head and these two interior cases still miss the rule.

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