Skip to content

Bug of matching absolute paths for some patterns. #46

@Isaac0616

Description

@Isaac0616

Some patterns work with both absolute and relative paths.
For example,

>>> list(pathspec.patterns.GitWildMatchPattern("*.py").match(["/foo/a.py", "foo/a.py", "x/foo/a.py", "/x/foo/a.py"]))
['/foo/a.py', 'foo/a.py', 'x/foo/a.py', '/x/foo/a.py']
>>> list(pathspec.patterns.GitWildMatchPattern("**").match(["/foo/a.py", "foo/a.py", "x/foo/a.py", "/x/foo/a.py"]))
['/foo/a.py', 'foo/a.py', 'x/foo/a.py', '/x/foo/a.py']

However, the pattern foo or /foo won't match the path starts with /foo.
For example,

>>> list(pathspec.patterns.GitWildMatchPattern("foo").match(["/foo/a.py", "foo/a.py", "x/foo/a.py", "/x/foo/a.py"]))
['foo/a.py', 'x/foo/a.py', '/x/foo/a.py']
>>> list(pathspec.patterns.GitWildMatchPattern("/foo").match(["/foo/a.py", "foo/a.py", "x/foo/a.py", "/x/foo/a.py"]))
['foo/a.py']

Can we support matching the absolute path in this case?
I think making output.append('(?:.+/)?') at here output.append('(?:.*/)?') could solve the issue, but I am not sure whether it has other unwanted side effect.
Another solution is that we normalize /... to ... similar to normalizing the ./ at here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions