From 8c32db36aaa0092790b39728b9c65a5f42c01e01 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 15 Sep 2024 08:51:37 +0200 Subject: [PATCH] pass CSV escape characters explicitly Not passing the $escape parameter is deprecated since PHP 8.4 as the default value will change in the future. --- .../Component/HttpKernel/Profiler/FileProfilerStorage.php | 4 ++-- .../HttpKernel/Tests/Profiler/FileProfilerStorageTest.php | 4 ++-- src/Symfony/Component/Translation/Dumper/CsvFileDumper.php | 2 +- .../Component/Validator/Resources/bin/sync-iban-formats.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php b/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php index 6fa24f1117ad1..8454060f9c9f5 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php +++ b/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php @@ -60,7 +60,7 @@ public function find(?string $ip, ?string $url, ?int $limit, ?string $method, ?i $result = []; while (\count($result) < $limit && $line = $this->readLineFromFile($file)) { - $values = str_getcsv($line); + $values = str_getcsv($line, ',', '"', '\\'); if (7 !== \count($values)) { // skip invalid lines @@ -187,7 +187,7 @@ public function write(Profile $profile): bool $profile->getTime(), $profile->getParentToken(), $profile->getStatusCode(), - ]); + ], ',', '"', '\\'); fclose($file); } diff --git a/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php b/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php index 8aede3181c85f..7802daa63f168 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php @@ -336,12 +336,12 @@ public function testMultiRowIndexFile() $handle = fopen($this->tmpDir.'/index.csv', 'r'); for ($i = 0; $i < $iteration; ++$i) { - $row = fgetcsv($handle); + $row = fgetcsv($handle, null, ',', '"', '\\'); $this->assertEquals('token'.$i, $row[0]); $this->assertEquals('127.0.0.'.$i, $row[1]); $this->assertEquals('http://foo.bar/'.$i, $row[3]); } - $this->assertFalse(fgetcsv($handle)); + $this->assertFalse(fgetcsv($handle, null, ',', '"', '\\')); } public function testReadLineFromFile() diff --git a/src/Symfony/Component/Translation/Dumper/CsvFileDumper.php b/src/Symfony/Component/Translation/Dumper/CsvFileDumper.php index 0c8589af81d79..3bb41f16bd141 100644 --- a/src/Symfony/Component/Translation/Dumper/CsvFileDumper.php +++ b/src/Symfony/Component/Translation/Dumper/CsvFileDumper.php @@ -31,7 +31,7 @@ public function formatCatalogue(MessageCatalogue $messages, string $domain, arra $handle = fopen('php://memory', 'r+'); foreach ($messages->all($domain) as $source => $target) { - fputcsv($handle, [$source, $target], $this->delimiter, $this->enclosure); + fputcsv($handle, [$source, $target], $this->delimiter, $this->enclosure, '\\'); } rewind($handle); diff --git a/src/Symfony/Component/Validator/Resources/bin/sync-iban-formats.php b/src/Symfony/Component/Validator/Resources/bin/sync-iban-formats.php index 6f2a9b049285b..b7c2e6d7d58a2 100755 --- a/src/Symfony/Component/Validator/Resources/bin/sync-iban-formats.php +++ b/src/Symfony/Component/Validator/Resources/bin/sync-iban-formats.php @@ -129,7 +129,7 @@ private function readPropertiesFromRegistry(array $properties): array array_shift($lines); foreach ($lines as $line) { - $columns = str_getcsv($line, "\t"); + $columns = str_getcsv($line, "\t", '"', '\\'); $propertyLabel = array_shift($columns); if (!isset($properties[$propertyLabel])) {