Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b3baa36

Browse filesBrowse files
committed
bug #54714 [Serializer] convert empty CSV header names into numeric keys (xabbuh)
This PR was merged into the 5.4 branch. Discussion ---------- [Serializer] convert empty CSV header names into numeric keys | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #54709 | License | MIT Commits ------- 93ee57b convert empty CSV header names into numeric keys
2 parents c1ca4ca + 93ee57b commit b3baa36
Copy full SHA for b3baa36

File tree

Expand file treeCollapse file tree

2 files changed

+17
-5
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-5
lines changed

‎src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/CsvEncoder.php
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,24 @@ public function decode(string $data, string $format, array $context = [])
181181
$depth = $headerCount[$i];
182182
$arr = &$item;
183183
for ($j = 0; $j < $depth; ++$j) {
184+
$headerName = $headers[$i][$j];
185+
186+
if ('' === $headerName) {
187+
$headerName = $i;
188+
}
189+
184190
// Handle nested arrays
185191
if ($j === ($depth - 1)) {
186-
$arr[$headers[$i][$j]] = $cols[$i];
192+
$arr[$headerName] = $cols[$i];
187193

188194
continue;
189195
}
190196

191-
if (!isset($arr[$headers[$i][$j]])) {
192-
$arr[$headers[$i][$j]] = [];
197+
if (!isset($arr[$headerName])) {
198+
$arr[$headerName] = [];
193199
}
194200

195-
$arr = &$arr[$headers[$i][$j]];
201+
$arr = &$arr[$headerName];
196202
}
197203
}
198204

‎src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,13 @@ public function testDecodeEmptyData()
218218
{
219219
$data = $this->encoder->decode("\n\n", 'csv');
220220

221-
$this->assertSame([['' => null]], $data);
221+
$this->assertSame([[0 => null]], $data);
222+
}
223+
224+
public function testMultipleEmptyHeaderNamesWithSeparator()
225+
{
226+
$this->encoder->decode(',.
227+
,', 'csv');
222228
}
223229

224230
public function testEncodeVariableStructure()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.