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 6c22622

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

File tree

2 files changed

+9
-1
lines changed
Filter options

2 files changed

+9
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/CsvEncoder.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php
+8Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.