Skip to content

glob.translate incorrectly matches path separator in character ranges #130942

Open
@euangoodbrand

Description

@euangoodbrand

Bug report

Bug description:

Description

The glob.translate function in Python 3.13 doesn't properly handle path separators when they're included in character ranges. According to the documentation, "wildcards do not match path separators," but this isn't enforced for character ranges that include the path separator.

Expected behavior

Character ranges in glob patterns should not match path separators, consistent with the behavior of single character wildcards (?) and the documented behavior of the module.

Actual behavior

Character ranges that include the path separator (e.g., [%-0] which includes the / character) will match the path separator, contradicting the documented behavior.

Code to reproduce

import glob
import re

# Proper behavior with ? wildcard
r1 = re.compile(glob.translate('a?c', seps=['/']))
print(r1)  # (?s:a[^/]c)\Z
print(r1.match('abc'))  # match object
print(r1.match('a/c'))  # None, correctly doesn't match path separator

# Incorrect behavior with character range
r2 = re.compile(glob.translate('a[%-0]c', seps=['/']))
print(r2)  # (?s:a[%-0]c)\Z
print(r2.match('a0c'))  # match object
print(r2.match('a/c'))  # match object, incorrectly matches path separator

### CPython versions tested on:

3.13

### Operating systems tested on:

_No response_

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions