Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Incorrect regex generated for patterns with ** #64

Open
Crell opened this issue Aug 10, 2024 · 1 comment
Open

Incorrect regex generated for patterns with ** #64

Crell opened this issue Aug 10, 2024 · 1 comment

Comments

@Crell
Copy link
Contributor

Crell commented Aug 10, 2024

I'm trying to filter some paths, where I want to use **. Unfortunately, the regex that's getting computed internal to Glob::filter() seems to be incorrect.

For example, the pattern /** compiles to ~^/[^/]*[^/]*$~. That will match /, /foo, /bar, but not /foo/bar. I believe it should be matching /foo/bar.

Similarly, the pattern /foo/** compiles to ~^/foo/[^/]*[^/]*$~. That will match /foo, /foo/bar, but not /foo/bar/baz.

So either there is a bug in the regex compiler in handling **, or I'm not understanding ** properly. I suppose either is possible. If there is some other way I should be doing this, please advise. (In practice I think I only need prefix-matching, but was trying to use a full glob for it for flexibility.)

@Ocramius
Copy link
Collaborator

Docs state /**/`` matches zero or more directory names: don't have any more context than that myself either :|

I see that the tests aren't matching descendants:

glob/tests/GlobTest.php

Lines 93 to 122 in 6712c9c

$this->assertSame(array(
$this->tempDir.'/css/reset.css',
$this->tempDir.'/css/style.css',
), Glob::glob($this->tempDir.'/*/**/*.css'));
$this->assertSame(array(
$this->tempDir.'/base.css',
$this->tempDir.'/css/reset.css',
$this->tempDir.'/css/style.css',
), Glob::glob($this->tempDir.'/**/*.css'));
$this->assertSame(array(
$this->tempDir.'/base.css',
$this->tempDir.'/css',
$this->tempDir.'/css/reset.css',
$this->tempDir.'/css/style.css',
), Glob::glob($this->tempDir.'/**/*css'));
$this->assertSame(array(
$this->tempDir.'/base.css',
$this->tempDir.'/css/reset.css',
), Glob::glob($this->tempDir.'/**/{base,reset}.css'));
$this->assertSame(array(
$this->tempDir.'/css',
$this->tempDir.'/css/reset.css',
$this->tempDir.'/css/style.css',
$this->tempDir.'/css/style.cts',
$this->tempDir.'/css/style.cxs',
), Glob::glob($this->tempDir.'/css{,/**/*}'));

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants