Skip to content

[Finder] Add double-star matching to Glob::toRegex() #21572

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2017

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

Adds ant-style /**/ matching to Glob::toRegex().

@fabpot
Copy link
Member

fabpot commented Feb 9, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 8b28afa into symfony:master Feb 9, 2017
fabpot added a commit that referenced this pull request Feb 9, 2017
…nicolas-grekas)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[Finder] Add double-star matching to Glob::toRegex()

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Adds ant-style `/**/` matching to `Glob::toRegex()`.

Commits
-------

8b28afa [Finder] Add double-star matching to Glob::toRegex()
@fabpot fabpot deleted the finder-glob branch February 9, 2017 10:23
$firstByte = '/' === $car;

if ($firstByte && $strictWildcardSlash && isset($glob[$i + 3]) && '**/' === $glob[$i + 1].$glob[$i + 2].$glob[$i + 3]) {
$car = $strictLeadingDot ? '/((?=[^\.])[^/]+/)*' : '/([^/]+/)*';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use a possessive quantifier for [^/]++/ to avoid useless backtracking.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in #21289

$firstByte = '/' === $car;

if ($firstByte && $strictWildcardSlash && isset($glob[$i + 3]) && '**/' === $glob[$i + 1].$glob[$i + 2].$glob[$i + 3]) {
$car = $strictLeadingDot ? '/((?=[^\.])[^/]+/)*' : '/([^/]+/)*';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shoudln't this use non-capturing groups ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants