Skip to content

ignore: handle escaped trailing whitespace#5095

Merged
ethomson merged 2 commits into
libgit2:masterfrom
pks-t:pks/ignore-escaped-trailing-space
Jun 6, 2019
Merged

ignore: handle escaped trailing whitespace#5095
ethomson merged 2 commits into
libgit2:masterfrom
pks-t:pks/ignore-escaped-trailing-space

Conversation

@pks-t
Copy link
Copy Markdown
Member

@pks-t pks-t commented Jun 6, 2019

The gitignore's pattern format specifies that "Trailing spaces
are ignored unless they are quoted with backslash ("")". We do
not honor this currently and will treat a pattern "foo\ " as if
it was "foo" only and a pattern "foo\ \ " as "foo\ ".

The current gitignore format does offer some very special
surprises, though: given a pattern "foo \ ", upstream git will in
fact strip all spaces and treat it as "foo", only.

Fix our code to handle those special cases and add tests to avoid
regressions.

The stripping of trailing spaces currently happens as part of
`git_attr_fnmatch__parse`. As we aren't currently parsing
trailing whitespaces correct in case they're escaped, we'll have
to change that code, though. To make actual behavioural change
easier to review, refactor the code up-front by pulling it out
into its own function that is expected to retain the exact same
functionality as before. Like this, the fix will be trivial to
apply.
@pks-t
Copy link
Copy Markdown
Member Author

pks-t commented Jun 6, 2019

@ethomson: I first thought that the things you discovered were weird. But this "foo \ " being treated as "foo" tops it all

@pks-t
Copy link
Copy Markdown
Member Author

pks-t commented Jun 6, 2019

I take that back. Seems like I just failed to use git-check-ignore correctly. Embarassing :/ Will amend

The gitignore's pattern format specifies that "Trailing spaces
are ignored unless they are quoted with backslash ("\")". We do
not honor this currently and will treat a pattern "foo\ " as if
it was "foo\" only and a pattern "foo\ \ " as "foo\ \".

Fix our code to handle those special cases and add tests to avoid
regressions.
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