Skip to content

[ Finder ] Static method Symfony\Component\Finder\Glob::toRegex() generates wrong regex for **/*.txt #62737

@TheCelavi

Description

@TheCelavi

Symfony version(s) affected

7.x.x

Description

Glob pattern **/*.txt will match path file.txt as well as foo/file.txt and so on.

However, Glob::toRegex('**/*.txt') generates regex which fails to match file.txt (it will match foo/file.txt).

Neither class Symfony\Component\Finder\Glob or its method toRegex() are not marked as @internal which encourages us to use it outside of symfony/finder context.

How to reproduce

Reproduction is trivial, use Glob::toRegex(**/*.txt) to generate regex and match that regex against file.txt. Matching should be positive.

Possible Solution

Unfortunately, I am unless here as I do not master regex/globs. It seams that function is port of Perl function, so maybe they fixed already, and that fix is not reflected in PHP port.

Additional Context

I honestly hope that you will keep this function as not internal :)

I believe that every version of symfony/finder is affected with the issue.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions