Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1fd5a2c

Browse files
bug #63064 [Translation] Fix handling of empty lines in CsvFileLoader (fnogatz)
This PR was submitted for the 8.1 branch but it was squashed and merged into the 6.4 branch instead. Discussion ---------- [Translation] Fix handling of empty lines in CsvFileLoader | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | (none) | License | MIT In its current version, the `CsvFileLoader` of [symfony/translation](https://github.com/symfony/translation) does not support empty lines within the CSV file due to a missing `SplFileObject::DROP_NEW_LINE` flag (cf. [PHP documentation](https://www.php.net/manual/en/class.splfileobject.php#splfileobject.constants)). Without this change, this would result in a warning like this: ``` CsvFileLoader.php:44 str_starts_with(): Passing null to parameter #1 ($haystack) of type string is deprecated ``` This PR changes the test file `resources.csv` to contain an empty line, and adds the missing flag in `CsvFileLoader::loadResource()`. I'm not sure whether this should be handled as a bugfix or new feature. Adding the flag doesn't break backward compatibility. Commits ------- 61a1414 [Translation] Fix handling of empty lines in CsvFileLoader
2 parents 61ff8e2 + 61a1414 commit 1fd5a2c

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/Symfony/Component/Translation/Loader/CsvFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function loadResource(string $resource): array
3434
throw new NotFoundResourceException(\sprintf('Error opening file "%s".', $resource), 0, $e);
3535
}
3636

37-
$file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
37+
$file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY | \SplFileObject::DROP_NEW_LINE);
3838
$file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
3939

4040
foreach ($file as $data) {
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"foo"; "bar"
22
#"bar"; "foo"
3+
4+
# all incorrect examples:
35
"incorrect"; "number"; "columns"; "will"; "be"; "ignored"
4-
"incorrect"
6+
"incorrect"

0 commit comments

Comments
 (0)