Skip to content

Commit 5297f35

Browse files
committed
Helpers::prepareAttrs() fixed
1 parent 9810d26 commit 5297f35

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/Forms/Helpers.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,15 @@ private static function prepareAttrs(?array $attrs, string $name): array
207207
{
208208
$dynamic = [];
209209
foreach ((array) $attrs as $k => $v) {
210-
$p = str_split($k, strlen($k) - 1);
211-
if ($p[1] === '?' || $p[1] === ':') {
212-
unset($attrs[$k], $attrs[$p[0]]);
213-
if ($p[1] === '?') {
214-
$dynamic[$p[0]] = array_fill_keys((array) $v, true);
210+
if ($k[-1] === '?' || $k[-1] === ':') {
211+
$p = substr($k, 0, -1);
212+
unset($attrs[$k], $attrs[$p]);
213+
if ($k[-1] === '?') {
214+
$dynamic[$p] = array_fill_keys((array) $v, true);
215215
} elseif (is_array($v) && $v) {
216-
$dynamic[$p[0]] = $v;
216+
$dynamic[$p] = $v;
217217
} else {
218-
$attrs[$p[0]] = $v;
218+
$attrs[$p] = $v;
219219
}
220220
}
221221
}

tests/Forms/Helpers.createSelectBox.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ test(function () {
5858
);
5959

6060
Assert::same(
61-
'<select><option title="Hello" style="color:blue" value="a" selected>First</option><option title="Hello" style="color:blue" value="b" disabled>Second</option></select>',
61+
'<select><option title="Hello" style="color:blue" a="b" value="a" selected>First</option><option title="Hello" style="color:blue" a="b" value="b" disabled>Second</option></select>',
6262
(string) Helpers::createSelectBox(
6363
['a' => 'First', 'b' => 'Second'],
6464
[
6565
'disabled:' => ['b' => true],
6666
'selected?' => ['a'],
6767
'title' => 'Hello',
6868
'style' => ['color' => 'blue'],
69+
'a' => 'b',
6970
]
7071
)
7172
);

0 commit comments

Comments
 (0)