Skip to content

Commit 1cf904b

Browse files
committed
test: bad header sanitized
1 parent 0cb5a10 commit 1cf904b

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/CsvFile.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ public function getHeaders(?int $length = null): array
135135
if ($headers === false) {
136136
return [];
137137
}
138-
$headers = array_map(fn ($header) => str_replace(["\r", "\n"], '', $header), $headers);
139138

140-
return $headers;
139+
return array_map(fn ($header) => str_replace(["\r", "\n"], '', $header), $headers);
141140
}
142141
}

tests/Feature/CsvFileTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,12 @@
5555
->and($content)->toContain('3,"Jane, Doe",3'.PHP_EOL)
5656
->and($content)->toContain('3,"Jane"" Doe",3'.PHP_EOL);
5757
});
58+
59+
test('it can sanitize headers', function () {
60+
$headers = CsvFile::make(__DIR__.'/../data/bad-header.dat', 'r')->getHeaders();
61+
expect($headers)->toBe([
62+
'NAME',
63+
'EMAIL',
64+
'PHONE',
65+
]);
66+
});

tests/data/bad-header.dat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
NAME,EMAIL,PHONE
2+
3+
4+
5+
"Mr. ""John"" Doe",[email protected]
6+
"Ms. Doe, Jane", [email protected]

0 commit comments

Comments
 (0)