8000 bug #57828 [Translation] Fix CSV escape char in `CsvFileLoader` on PH… · symfony/symfony@31e3abf · GitHub
[go: up one dir, main page]

Skip to content

Commit 31e3abf

Browse files
bug #57828 [Translation] Fix CSV escape char in CsvFileLoader on PHP >= 7.4 (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [Translation] Fix CSV escape char in `CsvFileLoader` on PHP >= 7.4 | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Related to #57827. This check has already been done in other places like: https://github.com/symfony/symfony/blob/4a176ceb4b67d1f17cdfb88ecc0946e47a807f65/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php#L310 Commits ------- 0507c22 [Translation] Fix CSV escape char in `CsvFileLoader` on PHP >= 7.4
2 parents 3621f80 + 0507c22 commit 31e3abf

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CsvFileLoader extends FileLoader
2222
{
2323
private $delimiter = ';';
2424
private $enclosure = '"';
25-
private $escape = '\\';
25+
private $escape = '';
2626

2727
/**
2828
* {@inheritdoc}
@@ -38,7 +38,7 @@ protected function loadResource(string $resource)
3838
}
3939

4040
$file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
41-
$file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
41+
$file->setCsvControl($this->delimiter, $this->enclosure, '' === $this->escape && \PHP_VERSION_ID < 70400 ? '\\' : $this->escape);
4242

4343
foreach ($file as $data) {
4444
if (false === $data) {
@@ -56,10 +56,10 @@ protected function loadResource(string $resource)
5656
/**
5757
* Sets the delimiter, enclosure, and escape character for CSV.
5858
*/
59-
public function setCsvControl(string $delimiter = ';', string $enclosure = '"', string $escape = '\\')
59+
public function setCsvControl(string $delimiter = ';', string $enclosure = '"', string $escape = '')
6060
{
6161
$this->delimiter = $delimiter;
6262
$this->enclosure = $enclosure;
63-
$this->escape = $escape;
63+
$this->escape = '' === $escape && \PHP_VERSION_ID < 70400 ? '\\' : $escape;
6464
}
6565
}

0 commit comments

Comments
 (0)
0