8000 bug #49245 [Serializer] Fix CsvEncoder decode on empty data (cazak) · symfony/symfony@fd2f680 · GitHub
[go: up one dir, main page]

Skip to content
10000

Commit fd2f680

Browse files
bug #49245 [Serializer] Fix CsvEncoder decode on empty data (cazak)
This PR was submitted for the 6.2 branch but it was merged into the 5.4 branch instead. Discussion ---------- [Serializer] Fix CsvEncoder decode on empty data | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Test that reproduces the error: https://gist.github.com/cazak/954d8bfe53d5b9139667eae8fe53957f The message i get after running the test: 1x: explode(): Passing null to parameter #2 ($string) of type string is deprecated 1x in CsvEncoderTest::testSuccess from App\Tests\Functional\Task Commits ------- 6c22622 [Serializer] Fix CsvEncoder decode on empty data
2 parents 7d3175e + 6c22622 commit fd2f680

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