Skip to content

Commit

Permalink
[Translation] Fix CSV escape char in CsvFileLoader on PHP >= 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-daubois committed Jul 26, 2024
1 parent bb51d7f commit 1d702ca
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Loader/CsvFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CsvFileLoader extends FileLoader
{
private $delimiter = ';';
private $enclosure = '"';
private $escape = '\\';
private $escape = '';

/**
* {@inheritdoc}
Expand All @@ -38,7 +38,7 @@ protected function loadResource(string $resource)
}

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

foreach ($file as $data) {
if (false === $data) {
Expand All @@ -56,10 +56,10 @@ protected function loadResource(string $resource)
/**
* Sets the delimiter, enclosure, and escape character for CSV.
*/
public function setCsvControl(string $delimiter = ';', string $enclosure = '"', string $escape = '\\')
public function setCsvControl(string $delimiter = ';', string $enclosure = '"', string $escape = '')
{
$this->delimiter = $delimiter;
$this->enclosure = $enclosure;
$this->escape = $escape;
$this->escape = '' === $escape && \PHP_VERSION_ID < 70400 ? '\\' : $escape;
}
}

0 comments on commit 1d702ca

Please sign in to comment.