10000 [Serializer] Fix CsvEncoder decode on empty data · symfony/symfony@6c22622 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c22622

Browse files
cazaknicolas-grekas
authored andcommitted
[Serializer] Fix CsvEncoder decode on empty data
1 parent 7d3175e commit 6c22622

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public function decode(string $data, string $format, array $context = [])
167167
$headerCount = array_fill(0, $nbCols, 1);
168168
} else {
169169
foreach ($cols as $col) {
170-
$header = explode($keySeparator, $col);
170+
$header = explode($keySeparator, $col ?? '');
171171
$headers[] = $header;
172172
$headerCount[] = \count($header);
173173
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ public function testEncodeEmptyArray()
211211
{
212212
$this->assertEquals("\n\n", $this->encoder->encode([], 'csv'));
213213
$this->assertEquals("\n\n", $this->encoder->encode([[]], 'csv'));
214+
$this->assertEquals("\n\n", $this->encoder->encode([['' => null]], 'csv'));
215+
}
216+
217+
public function testDecodeEmptyData()
218+
{
219+
$data = $this->encoder->decode("\n\n", 'csv');
220+
221+
$this->assertSame([['' => null]], $data);
214222
}
215223

216224
public function testEncodeVariableStructure()

0 commit comments

Comments
 (0)
0