You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue affects version 3.5.5 and is very closely related to #1920
The problem
Imagine I want to exclude files in bin directories:
<exclude-pattern>*/bin/*</exclude-pattern>
This rule will also match and exclude any directory starting with bin, such as ./src/BingSearch/
The problem appears to be in the same area of code that caused #1920, specifically Filter.php#L221:
if (substr($pattern, -2) === '/*') {
// Need to check this pattern for dirs as well as individual file paths.$this->ignoreFilePatterns[$pattern] = $type;
$pattern = substr($pattern, 0, -2);
$this->ignoreDirPatterns[$pattern] = $type;
} else {
// This is a file-specific pattern, so only need to check this// for individual file paths.$this->ignoreFilePatterns[$pattern] = $type;
}
Removing the trailing slash with substr allows the pattern to match the directory, but it also allows it to match any directory with a name that starts the same.
Proposed solution
A simple fix is to anchor the directory pattern to the end of the string, like this:
This issue affects version 3.5.5 and is very closely related to #1920
The problem
Imagine I want to exclude files in
bin
directories:This rule will also match and exclude any directory starting with
bin
, such as./src/BingSearch/
The problem appears to be in the same area of code that caused #1920, specifically Filter.php#L221:
Removing the trailing slash with
substr
allows the pattern to match the directory, but it also allows it to match any directory with a name that starts the same.Proposed solution
A simple fix is to anchor the directory pattern to the end of the string, like this:
Or use a lookahead:
Workaround
To exclude files in
bin
directories, use a lookahead in the exclude pattern inphpcs.xml
:The text was updated successfully, but these errors were encountered: