Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leading & trailing whitespace #86

Open
CarterFendley opened this issue Jun 16, 2024 · 1 comment
Open

Leading & trailing whitespace #86

CarterFendley opened this issue Jun 16, 2024 · 1 comment

Comments

@CarterFendley
Copy link

Hello, I am using this library and noticing some odd results around white space. When the white space is leading or trailing, I do not get any matches.

# Leading whitespace does not match
>>> pathspec.PathSpec.from_lines(pathspec.patterns.GitWildMatchPattern, ['   whitespace.txt']).match_file('   whitespace.txt')
False

# Trailing whitespace does not match
>>> pathspec.PathSpec.from_lines(pathspec.patterns.GitWildMatchPattern, ['whitespace.txt   ']).match_file('whitespace.txt   ')
False

It seems to have no problem with whitespace internal to a string.

>>> pathspec.PathSpec.from_lines(pathspec.patterns.GitWildMatchPattern, ['white   space.txt']).match_file('white   space.txt')
True

Can you help me understand what is going on here? Both whitespace.txt and whitespace.txt are valid file names so I would like to figure out why I can't match them.

@cpburnz
Copy link
Owner

cpburnz commented Jun 27, 2024

You have to escape leading and trailing spaces in patterns in order to match them in file names.

# Leading whitespace.
>>> pathspec.PathSpec.from_lines(pathspec.patterns.GitWildMatchPattern, ['\\ \\ \\ whitespace.txt']).match_file('   whitespace.txt')
True

# Trailing whitespace.
>>> pathspec.PathSpec.from_lines(pathspec.patterns.GitWildMatchPattern, ['whitespace.txt\\ \\ \\ ']).match_file('whitespace.txt   ')
True

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

No branches or pull requests

2 participants