Skip to content

Incorrect suffixMatch optimization of ** #12

Description

@mtrmac

2d3e837 introduced matchType to speed up matching; that changed semantics of **.

https://docs.docker.com/build/concepts/context/#matching says ** … matches any number of directories (including zero)”. (https://git-scm.com/docs/gitignore is even more restrictive).

But consider these added test cases:

diff --git a/patternmatcher_test.go b/patternmatcher_test.go
index 5f02521..81d73fd 100644
--- a/patternmatcher_test.go
+++ b/patternmatcher_test.go
@@ -184,6 +184,14 @@ func TestMatches(t *testing.T) {
                {"a.|)$(}+{bc", "a.|)$(}+{bc", true},
                {"dist/proxy.py-2.4.0rc3.dev36+g08acad9-py3-none-any.whl", "dist/proxy.py-2.4.0rc3.dev36+g08acad9-py3-none-any.whl", true},
                {"dist/*.whl", "dist/proxy.py-2.4.0rc3.dev36+g08acad9-py3-none-any.whl", true},
+               {"**.md", ".md", true},
+               {"**.md", "name.md", true},
+               {"**.md", "dir/.md", true},
+               {"**.md", "dir/name.md", true},
+               {"**.m[dD]", ".md", true},
+               {"**.m[dD]", "name.md", false},
+               {"**.m[dD]", "dir/.md", true},
+               {"**.m[dD]", "dir/name.md", false},
        }
        multiPatternTests := []multiPatternTestCase{
                {[]string{"**", "!util/docker/web"}, "util/docker/web/foo", false},

The suffixMatch code path is a simple suffix, so name.md and dir/name.md match; the regexpMatch code path uses (.*/)?, so name.md and dir/name.md don’t match.


(On the other side of **, matching is also not interpreting the value as “any number of directories”, d** matches dir/name.md, but at least it is consistent between prefixMatch and regexpMatch.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions