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

Fix "a/**/b" matching "a/bb" #56

Conversation

jherland
Copy link
Contributor

@jherland jherland commented Oct 3, 2023

Quoting https://git-scm.com/docs/gitignore#_pattern_format:

A slash followed by two consecutive asterisks then a slash matches
zero or more directories. For example, "a/**/b" matches "a/b",
"a/x/b", "a/x/y/b" and so on.

I read this to mean that the "/**/" pattern should only match at
directory boundaries, i.e. it is NOT meant to be equivalent to "/**".

Fix this by making the last '/' mandatory when the preceding ".*"
regex match is non-empty.

In other words, for "/**/" patterns, change the resulting regex from
[/].*[/]?
to
[/](.*[/])?

Quoting https://git-scm.com/docs/gitignore#_pattern_format:

  A slash followed by two consecutive asterisks then a slash matches
  zero or more directories. For example, "a/**/b" matches "a/b",
  "a/x/b", "a/x/y/b" and so on.

I read this to mean that the "/**/" pattern should only match at
directory boundaries, i.e. it is NOT meant to be equivalent to "/**".

Fix this by making the last '/' mandatory when the preceding ".*"
regex match is non-empty.

In other words, for "/**/" patterns, change the resulting regex from
  [/].*[/]?
to
  [/](.*[/])?
@mherrmann mherrmann merged commit 6abc776 into mherrmann:master Oct 4, 2023
5 checks passed
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