Skip to content

Commit aa00185

Browse files
committed
Ruleset::processRule(): fix edge case bug - inconsistent handling of empty string array key
Unlikely scenario for real-life, but still a bug. When an array property is set via the old comma-separated string ruleset format or via an inline `phpcs:set` annotation, and the key for an array element would be explicitly set to an empty string, the resulting array item in the property on the sniff class would be added without a key, resulting in a numeric key. However, if the (not so) "new" ruleset format using `<element>` nodes is used and an array element key is an empty string, this would result in the array item being added with an empty string for the array key. This is inconsistent behaviour and is now fixed. As 2 out of 3 scenarios would result in a numeric key, the behaviour has now been standardized as such. This can be revisited, if needs be, at a later point in time.
1 parent e38b254 commit aa00185

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Ruleset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ private function processRule($rule, $newSniffs, $depth=0)
12151215
}
12161216

12171217
$value = (string) $element['value'];
1218-
if (isset($element['key']) === true) {
1218+
if (isset($element['key']) === true && trim($element['key']) !== '') {
12191219
$key = (string) $element['key'];
12201220
$values[$key] = $value;
12211221
$printValue .= $key.'=>'.$value.',';

0 commit comments

Comments
 (0)