8000 [Serializer] convert empty CSV header names into numeric keys by xabbuh · Pull Request #54714 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] convert empty CSV header names into numeric keys #54714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Symfony/Component/Serializer/Encoder/CsvEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,24 @@
$depth = $headerCount[$i];
$arr = &$item;
for ($j = 0; $j < $depth; ++$j) {
$headerName = $headers[$i][$j];

if ('' === $headerName) {
$headerName = $i;
}

// Handle nested arrays
if ($j === ($depth - 1)) {
$arr[$headers[$i][$j]] = $cols[$i];
$arr[$headerName] = $cols[$i];

Check failure on line 192 in src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArrayOffset

src/Symfony/Component/Serializer/Encoder/CsvEncoder.php:192:25: InvalidArrayOffset: Cannot access value on variable $arr[$headerName] using a ''|int<0, max>|non-empty-string offset, expecting int (see https://psalm.dev/115)

Check failure on line 192 in src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArrayOffset

src/Symfony/Component/Serializer/Encoder/CsvEncoder.php:192:25: InvalidArrayOffset: Cannot access value on variable $arr[$headerName] using a ''|int<0, max>|non-empty-string offset, expecting int (see https://psalm.dev/115)

continue;
}

if (!isset($arr[$headers[$i][$j]])) {
$arr[$headers[$i][$j]] = [];
if (!isset($arr[$headerName])) {
$arr[$headerName] = [];

Check failure on line 198 in src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArrayOffset

src/Symfony/Component/Serializer/Encoder/CsvEncoder.php:198:25: InvalidArrayOffset: Cannot access value on variable $arr[$headerName] using a ''|int<0, max>|non-empty-string offset, expecting int (see https://psalm.dev/115)

Check failure on line 198 in src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArrayOffset

src/Symfony/Component/Serializer/Encoder/CsvEncoder.php:198:25: InvalidArrayOffset: Cannot access value on variable $arr[$headerName] using a ''|int<0, max>|non-empty-string offset, expecting int (see https://psalm.dev/115)
}

$arr = &$arr[$headers[$i][$j]];
$arr = &$arr[$headerName];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,13 @@ public function testDecodeEmptyData()
{
$data = $this->encoder->decode("\n\n", 'csv');

$this->assertSame([['' => null]], $data);
$this->assertSame([[0 => null]], $data);
}

public function testMultipleEmptyHeaderNamesWithSeparator()
{
$this->encoder->decode(',.
,', 'csv');
}

public function testEncodeVariableStructure()
Expand Down
Loading
0