Skip to content

Commit fbbe2cf

Browse files
authored
Fix #44: Fix error in Html::renderSelectOptions when use "encode" as key in items array
1 parent b778179 commit fbbe2cf

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"require-dev": {
2323
"phpunit/phpunit": "^9.4",
24-
"roave/infection-static-analysis-plugin": "^1.5",
24+
"roave/infection-static-analysis-plugin": "^1.6",
2525
"spatie/phpunit-watcher": "^1.23",
2626
"vimeo/psalm": "^4.2"
2727
},

src/Html.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,8 +1417,6 @@ public static function renderSelectOptions($selection, array $items, array &$tag
14171417
$options = $tagOptions['options'] ?? [];
14181418
$groups = $tagOptions['groups'] ?? [];
14191419
unset($tagOptions['prompt'], $tagOptions['options'], $tagOptions['groups']);
1420-
$options['encodeSpaces'] = ArrayHelper::getValue($options, 'encodeSpaces', $encodeSpaces);
1421-
$options['encode'] = ArrayHelper::getValue($options, 'encode', $encode);
14221420

14231421
foreach ($items as $key => $value) {
14241422
if (is_array($value)) {

tests/HtmlTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,17 @@ public function testRenderSelectOptions(): void
10151015
],
10161016
];
10171017
$this->assertSameWithoutLE($expected, Html::renderSelectOptions(1, $data, $attributes));
1018+
1019+
$expected = <<<'EOD'
1020+
<option value="encode">1</option>
1021+
<option value="encodeSpaces">2</option>
1022+
EOD;
1023+
$data = ['encode' => 1, 'encodeSpaces' => 2];
1024+
$attributes = [
1025+
'encode' => true,
1026+
'encodeSpaces' => false,
1027+
];
1028+
$this->assertSameWithoutLE($expected, Html::renderSelectOptions(null, $data, $attributes));
10181029
}
10191030

10201031
public function testRenderAttributes(): void

0 commit comments

Comments
 (0)