Skip to content

Keep non-space filename characters when trimming gitignore patterns - #150

Merged
cpburnz merged 1 commit into
cpburnz:masterfrom
Metis-dot:fix/preserve-literal-trailing-characters
Oct 7, 2026
Merged

cpburnz merged 1 commit into
cpburnz:masterfrom
Metis-dot:fix/preserve-literal-trailing-characters

Conversation

@Metis-dot

Copy link
Copy Markdown
Contributor

Summary

Gitignore patterns ending in a TAB or a non-ASCII space currently match the filename without that character and miss the literal filename. For example, GitIgnoreSpec.from_lines(['example\t'], backend='simple') ignores example rather than example\t. This reproduces with the official 1.1.1 wheel and current master; Git 2.52.0 retains the TAB.

The released parser uses a broad rstrip() and master's _strip_trailing_ws() uses str.isspace(). Both can also truncate UTF-8 NBSP bytes: the pattern b'mark\xc2\xa0\n' misses the full name and matches b'mark\xc2' instead.

Limit the existing scan to spaces and CR/LF, retaining literal TAB, vertical tab, form feed, NEL, NBSP, and EM SPACE characters. Backslash parity and existing CR/LF handling are preserved. This does not attempt to fix the separate existing CR/LF edge cases.

Validation

  • Both pattern classes are covered with string and compiled-byte patterns, escaped names, ordinary ASCII-space/backslash controls, LF/CRLF stream inputs, negation, directory rules, and a literal whitespace component immediately after a slash
  • New regression module: 117 failing subtests on the unchanged master; passes with the patch
  • Focused tests: 11 passed
  • Full python -m unittest discover -t . -s tests/: 230 passed, 385 skipped subtests. Optional RE2/Hyperscan backends were not installed or tested
  • Independent real-Git oracle: 53 fixtures across four input forms, 212 comparisons; 100 mismatches corrected, zero new mismatches. Separate final-byte coverage: 506 comparisons across both pattern classes, all agreeing with Git after the patch
  • Repository mypy pathspec tests/check_usage.py and pyright pathspec tests/check_usage.py report the same 9 and 8 diagnostics, respectively, before and after the patch. These concern missing optional backends and existing _typing.py issues; no new diagnostic was introduced
  • The changed/new test modules have zero pyright errors; compileall and git diff --check pass

The commands were executed in an isolated CPython 3.12.14 environment using official PyPI wheels, with Git 2.52.0 as the matching oracle.

AI assistance: the patch and tests were prepared with an OpenAI assistant. All reported verification was actually executed, and another AI assistant independently reviewed and reran the relevant tests and Git comparisons. This does not represent human review.

@cpburnz
cpburnz marked this pull request as ready for review October 7, 2026 02:53
@cpburnz
cpburnz merged commit 25e1bdf into cpburnz:master Oct 7, 2026
7 checks passed
@cpburnz

cpburnz commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Thanks for finding this. I should have verified the trailing whitespace behavior more closely.

cpburnz added a commit that referenced this pull request Oct 8, 2026
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.

2 participants