Skip to content

Commit 482b9d7

Browse files
[Translation] Fix CSV escape char in CsvFileLoader on PHP >= 7.4
1 parent 4a176ce commit 482b9d7

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy