Skip to content

glob.translate does not correctly handle ] as first character in character class #130985

@dkaszews

Description

@dkaszews

Bug report

Bug description:

> import glob
> glob.translate('[][!]')
(?s:[][!])\Z

This specific example is explicitly mentioned in man glob:

The string enclosed by the
brackets cannot be empty; therefore ']' can be allowed between the
brackets, provided that it is the first character. (Thus, "[][!]"
matches the three characters '[', ']', and '!'.)

Therefore, the expected regex would be (?s:[\[\]!])\Z, while the actual one simplifies to just (?s:!)\Z, only matching literal '!'.

Related to #130942 , where character classes do not correctly handle path separator.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directory

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions