Skip to content

glob.translate("a/**/c", recursive=True, include_hidden=True) does not match "a//c" #116393

@ap--

Description

@ap--

Bug report

Bug description:

The pattern returned by glob.translate("a/**/c", recursive=True, include_hidden=True) currently does not match paths that have two slashes "//" between two parts:

import glob

pattern = glob.translate("a/**/c", recursive=True, include_hidden=True)
# '(?s:a/(?:.+/)?c)\\Z'

assert re.match(pattern, "a/c")    # match
assert re.match(pattern, "a/b/c")  # match
assert re.match(pattern, "a//c")   # None
assert re.match(pattern, "a///c")  # match

It looks like the fix should be simple and requires replacing .+ with .* in

any_segments = f'(?:.+{any_sep})?'

I'd be happy to add tests and apply the fix in a PR.

Cheers,
Andreas

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions