Skip to content

Handle escaped internal separators in gitignore patterns - #170

Open
KennyMcSimpson wants to merge 1 commit into
cpburnz:masterfrom
KennyMcSimpson:fix/escaped-gitignore-separators
Open

KennyMcSimpson wants to merge 1 commit into
cpburnz:masterfrom
KennyMcSimpson:fix/escaped-gitignore-separators

Conversation

@KennyMcSimpson

Copy link
Copy Markdown

Gitignore patterns with escaped internal separators are currently discarded as if they contained a trailing backslash. For example, with a real build/output.txt file and build\/output.txt in .gitignore, Git ignores the file, but GitIgnoreSpec.from_lines([r"build\/output.txt"]).match_file("build/output.txt") returns False.

Account for the separator following each pattern segment before treating its last backslash as invalid. Preserve backslash parity, directory-only patterns, and Git's distinction between **/b and **\/b: the escaped slash must still be present. Escaped leading slashes remain literal, and escaped terminal slashes remain invalid. Existing segment-translator overrides keep their original calling convention.

Regression tests cover literal paths, globs, negated rules, text/byte patterns, and all three backends. The new tests fail on the unchanged base and pass after the fix; all 46 targeted Git comparison cases agree with git check-ignore.

Validation on Python 3.13 / Windows: tox -e ci-base,ci-hyperscan,ci-re2 and tox -e docs pass. With both optional backends installed, python -m unittest discover -t . -s tests/ passes all 295 tests (16 existing platform skips). mypy pathspec tests/check_usage.py and git diff --check pass.

AI assistance: prepared with OpenAI Codex, with the reproduction and regression checks described above.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant