8000 fixed #18843 (fixed detection of normal/associative arrays) · symfony/symfony@64b0531 · GitHub
[go: up one dir, main page]

Skip to content

Commit 64b0531

Browse files
author
Anton Bakai
committed
fixed #18843 (fixed detection of normal/associative arrays)
1 parent 65b517b commit 64b0531

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 15 additions & 5 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,22 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp
156156
*/
157157
private static function dumpArray($value, $exceptionOnInvalidType, $objectSupport)
158158
{
159+
if ($value) {
160+
$expectedKey = 0;
161+
$isMapping = false;
162+
163+
foreach ($value as $key => $val) {
164+
if ($key !== $expectedKey++) {
165+
$isMapping = true;
166+
break;
167+
}
168+
}
169+
} else {
170+
$isMapping = true;
171+
}
172+
159173
// array
160-
$keys = array_keys($value);
161-
$keysCount = count($keys);
162-
if ((1 === $keysCount && '0' == $keys[0])
163-
|| ($keysCount > 1 && array_reduce($keys, function ($v, $w) { return (int) $v + $w; }, 0) === $keysCount * ($keysCount - 1) / 2)
164-
) {
174+
if (!$isMapping) {
165175
$output = array();
166176
foreach ($value as $val) {
167177
$output[] = self::dump($val, $exceptionOnInvalidType, $objectSupport);

0 commit comments

Comments
 (0)
0