Skip to content

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

@jpuck

Description

@jpuck

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions