Skip to content

Commit e8f2c75

Browse files
committed
Ruleset::processRule(): fix handling of rules included via path
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
1 parent 040a7a6 commit e8f2c75

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/Ruleset.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -861,11 +861,17 @@ private function processRule($rule, $newSniffs, $depth=0)
861861
$ref = (string) $rule['ref'];
862862
$todo = [$ref];
863863

864-
$parts = explode('.', $ref);
865-
if (count($parts) <= 2) {
866-
// We are processing a standard or a category of sniffs.
864+
$parts = explode('.', $ref);
865+
$partsCount = count($parts);
866+
if ($partsCount <= 2 || $partsCount > count(array_filter($parts))) {
867+
// We are processing a standard, a category of sniffs or a relative path inclusion.
867868
foreach ($newSniffs as $sniffFile) {
868-
$parts = explode(DIRECTORY_SEPARATOR, $sniffFile);
869+
$parts = explode(DIRECTORY_SEPARATOR, $sniffFile);
870+
if (count($parts) === 1 && DIRECTORY_SEPARATOR === '\\') {
871+
// Path using forward slashes while running on Windows.
872+
$parts = explode('/', $sniffFile);
873+
}
874+
869875
$sniffName = array_pop($parts);
870876
$sniffCategory = array_pop($parts);
871877
array_pop($parts);

0 commit comments

Comments
 (0)