Skip to content

Commit 38a40fd

Browse files
authored
Merge pull request #1193 from PHPCSStandards/feature/ruleset-document-handling-empty-string-in-array
Ruleset::processRule(): fix edge case bug - inconsistent handling of empty string array key
2 parents 9779433 + 0fc21dd commit 38a40fd

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
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.',';

tests/Core/Ruleset/Fixtures/PropertyTypeHandlingInline.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsBooleanFalseCase fALSe
2121
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsBooleanFalseTrimmed false
2222

23-
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithOnlyValues[] string, 10, 1.5, null, true, false
24-
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithKeysAndValues[] string=>string,10=>10,float=>1.5,null=>null,true=>true,false=>false
23+
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithOnlyValues[] string, 10, 1.5, , null, true, false
24+
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsArrayWithKeysAndValues[] string=>string,10=>10,float=>1.5,=>,null=>null,true=>true,false=>false
2525
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsEmptyArray[]
2626

27-
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsOldSchoolArrayWithOnlyValues[] string, 10, 1.5, null, true, false
28-
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsOldSchoolArrayWithKeysAndValues[] string=>string,10=>10,float=>1.5,null=>null,true=>true,false=>false
27+
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsOldSchoolArrayWithOnlyValues[] string, 10, 1.5, , null, true, false
28+
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsOldSchoolArrayWithKeysAndValues[] string=>string,10=>10,float=>1.5,=>,null=>null,true=>true,false=>false
2929
// phpcs:set TestStandard.SetProperty.PropertyTypeHandling expectsOldSchoolEmptyArray[]
3030

3131
echo 'hello!';

tests/Core/Ruleset/PropertyTypeHandlingTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public static function dataTypeHandling()
120120
'string',
121121
'10',
122122
'1.5',
123+
'',
123124
'null',
124125
'true',
125126
'false',
@@ -128,6 +129,7 @@ public static function dataTypeHandling()
128129
'string' => 'string',
129130
10 => '10',
130131
'float' => '1.5',
132+
11 => '',
131133
'null' => 'null',
132134
'true' => 'true',
133135
'false' => 'false',

tests/Core/Ruleset/PropertyTypeHandlingTest.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<element value="string"/>
2626
<element value="10"/>
2727
<element value="1.5"/>
28+
<element value=""/>
2829
<element value="null"/>
2930
<element value="true"/>
3031
<element value="false"/>
@@ -34,6 +35,7 @@
3435
<element key="string" value="string"/>
3536
<element key="10" value="10"/>
3637
<element key="float" value="1.5"/>
38+
<element key="" value=""/>
3739
<element key="null" value="null"/>
3840
<element key="true" value="true"/>
3941
<element key="false" value="false"/>
@@ -60,9 +62,9 @@
6062

6163
<property name="expectsEmptyArray" type="array"/>
6264

63-
<property name="expectsOldSchoolArrayWithOnlyValues" type="array" value="string, 10, 1.5, null, true, false" />
65+
<property name="expectsOldSchoolArrayWithOnlyValues" type="array" value="string, 10, 1.5, , null, true, false" />
6466

65-
<property name="expectsOldSchoolArrayWithKeysAndValues" type="array" value="string=>string,10=>10,float=>1.5,null=>null,true=>true,false=>false" />
67+
<property name="expectsOldSchoolArrayWithKeysAndValues" type="array" value="string=>string,10=>10,float=>1.5,=>,null=>null,true=>true,false=>false" />
6668

6769
<property name="expectsOldSchoolArrayWithExtendedValues" type="array" value="string" />
6870
<property name="expectsOldSchoolArrayWithExtendedValues" type="array" extend="true" value="15,another string" />

0 commit comments

Comments
 (0)