Skip to content

Commit

Permalink
Ruleset::processRule(): fix handling of rules included via path
Browse files Browse the repository at this point in the history
This fixes a bug where properties set for rules included via a path to the sniff file or to an included standards file, would be disregarded if the slashes used in the path did not match the slashes expected for the OS on which the ruleset is being run.

Fixes 2497
  • Loading branch information
jrfnl committed Sep 22, 2019
1 parent 040a7a6 commit e8f2c75
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Ruleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,17 @@ private function processRule($rule, $newSniffs, $depth=0)
$ref = (string) $rule['ref'];
$todo = [$ref];

$parts = explode('.', $ref);
if (count($parts) <= 2) {
// We are processing a standard or a category of sniffs.
$parts = explode('.', $ref);
$partsCount = count($parts);
if ($partsCount <= 2 || $partsCount > count(array_filter($parts))) {
// We are processing a standard, a category of sniffs or a relative path inclusion.
foreach ($newSniffs as $sniffFile) {
$parts = explode(DIRECTORY_SEPARATOR, $sniffFile);
$parts = explode(DIRECTORY_SEPARATOR, $sniffFile);
if (count($parts) === 1 && DIRECTORY_SEPARATOR === '\\') {
// Path using forward slashes while running on Windows.
$parts = explode('/', $sniffFile);
}

$sniffName = array_pop($parts);
$sniffCategory = array_pop($parts);
array_pop($parts);
Expand Down

0 comments on commit e8f2c75

Please sign in to comment.