One function
rule_from_pattern in mherrmann/gitignore_parser
The author described this change as “Fix patterns with leading exclamation marks (#54)”. It counts as a record because the check below fails on the code as it stood at d45a08589 and passes on 1040aa547, with nothing else changed between the two runs.
Projectmherrmann/gitignore_parser
Fix saved2023-10-03
Sharing licenceMIT · LICENSE
Change size+3 −2
What the code was meant to do, written into the code itself as a docstring
Take a .gitignore match pattern, such as "*.py[cod]" or "**/*.bak", and return an IgnoreRule suitable for matching against files and directories. Patterns which do not match files, such as comments and blank lines, will return None. Because git allows for nested .gitignore files, a base_path value is required for correct behavior. The base path should be absolute.
The change
| 50 | 50 | pattern = pattern[1:] | |
| 51 | 51 | if pattern[-1] == '/': | |
| 52 | 52 | pattern = pattern[:-1] | |
| 53 | - | # patterns with leading hashes are escaped with a backslash in front, unescape it | |
| 54 | - | if pattern[0] == '\\' and pattern[1] == '#': | |
| 53 | + | # patterns with leading hashes or exclamation marks are escaped with a | |
| 54 | + | # backslash in front, unescape it | |
| 55 | + | if pattern[0] == '\\' and pattern[1] in ('#', '!'): | |
| 55 | 56 | pattern = pattern[1:] | |
| 56 | 57 | # trailing spaces are ignored unless they are escaped with a backslash | |
| 57 | 58 | i = len(pattern)-1 |
The check that tells the two apart
fail→pass·tests.py::Test::test_literal_exclamation_mark
Check file tests.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before itd45a0858926f8db2fe627fea9e99d794d264dabf
Broken version dated2023-10-03
Modulegitignore_parser
Units changedrule_from_pattern
Fingerprint0c0bd906f07400ce
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in mherrmann/gitignore_parser
- 2024-01-19Fix ValueError for some symlinks
- 2023-10-05Fix: do not resolve symlinks
- 2023-10-04rule_from_pattern
- 2023-10-04fnmatch_pathname_to_regex
- 2023-10-03fnmatch_pathname_to_regex
- 2023-06-30fnmatch_pathname_to_regex