Skip to content
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

Directory exclude pattern improperly excludes files with names that start the same #1920

Closed
jpuck opened this issue Mar 2, 2018 · 1 comment
Milestone

Comments

@jpuck
Copy link

jpuck commented Mar 2, 2018

Consider I would like to exclude files in bin directories:

<exclude-pattern>*/bin/*</exclude-pattern>

Unfortunately, this rule will also match ./src/BingSearch.php

I don't have time right now to write a properly tested PR, but I believe the issue is on Filter.php#L207.

if (substr($pattern, -2) === '/*') {
    // Need to check this pattern for dirs as well as individual file paths.
    $pattern = substr($pattern, 0, -2);
    $this->ignoreDirPatterns[$pattern]  = $type;
    $this->ignoreFilePatterns[$pattern] = $type;

So in this case it will strip that trailing slash to identify directories, but it also adds that pattern to the files array. I think this can be remedied by leaving the slash on for file patterns and only removing it for directory patterns, e.g.

$dirPattern = substr($pattern, 0, -2); // removes trailing slash
$this->ignoreDirPatterns[$dirPattern] = $type;

$filePattern = substr($pattern, 0, -1); // preserves trailing slash
$this->ignoreFilePatterns[$filePattern] = $type;
@gsherwood gsherwood added this to the 3.3.0 milestone Mar 12, 2018
@gsherwood gsherwood changed the title directory exclude pattern improperly excludes files with names that start the same Directory exclude pattern improperly excludes files with names that start the same Mar 20, 2018
gsherwood added a commit that referenced this issue Mar 20, 2018
@gsherwood
Copy link
Member

Thanks for reporting this, and thanks for your suggested changes. I ended up leaving the pattern as-is for file checking and only doing the substr for the directories.

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

No branches or pull requests

2 participants