From 35d9969bc56d7644849446fb370cc8dd072bea4b Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Tue, 19 Nov 2024 09:50:21 +0000 Subject: [PATCH] Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4 (cherry picked from commit 9cf58fe16c520270149e9698bd7d75021ef5dee1) --- core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php | 2 +- core/lib/Drupal/Core/Mail/Plugin/Mail/SymfonyMailer.php | 2 +- .../tests/src/Traits/ValidateMigrationStateTestTrait.php | 4 ++-- .../modules/demo_umami_content/src/InstallHelper.php | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php b/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php index a578a0246390..1db46cf97c33 100644 --- a/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php +++ b/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php @@ -98,7 +98,7 @@ public function mail(array $message) { if (in_array(strtolower($name), self::MAILBOX_LIST_HEADERS, TRUE)) { // Split values by comma, but ignore commas encapsulated in double // quotes. - $value = str_getcsv($value, ','); + $value = str_getcsv($value, escape: '\\'); } $headers->addHeader($name, $value); } diff --git a/core/lib/Drupal/Core/Mail/Plugin/Mail/SymfonyMailer.php b/core/lib/Drupal/Core/Mail/Plugin/Mail/SymfonyMailer.php index 80b545465e42..83bf5c127fad 100644 --- a/core/lib/Drupal/Core/Mail/Plugin/Mail/SymfonyMailer.php +++ b/core/lib/Drupal/Core/Mail/Plugin/Mail/SymfonyMailer.php @@ -127,7 +127,7 @@ public function mail(array $message) { if (in_array(strtolower($name), self::MAILBOX_LIST_HEADERS, TRUE)) { // Split values by comma, but ignore commas encapsulated in double // quotes. - $value = str_getcsv($value, ','); + $value = str_getcsv($value, escape: '\\'); } $headers->addHeader($name, $value); } diff --git a/core/modules/migrate_drupal/tests/src/Traits/ValidateMigrationStateTestTrait.php b/core/modules/migrate_drupal/tests/src/Traits/ValidateMigrationStateTestTrait.php index 56367c808ee5..010f346ce9ad 100644 --- a/core/modules/migrate_drupal/tests/src/Traits/ValidateMigrationStateTestTrait.php +++ b/core/modules/migrate_drupal/tests/src/Traits/ValidateMigrationStateTestTrait.php @@ -125,7 +125,7 @@ public function testMigrationState(): void { // Assert that each discovered migration has a corresponding declaration // in a migrate_drupal.yml. foreach ($discovered_unique as $datum) { - $data = str_getcsv($datum); + $data = str_getcsv($datum, escape: ''); $in_finished = in_array($datum, $declared_unique[MigrationState::FINISHED]); $in_not_finished = in_array($datum, $declared_unique[MigrationState::NOT_FINISHED]); $found = $in_finished || $in_not_finished; @@ -137,7 +137,7 @@ public function testMigrationState(): void { // not finished. $discovered_not_finished = array_diff($discovered_unique, $declared_unique[MigrationState::FINISHED]); foreach ($discovered_not_finished as $datum) { - $data = str_getcsv($datum); + $data = str_getcsv($datum, escape: ''); $this->assertContains($datum, $declared_unique[MigrationState::NOT_FINISHED], sprintf("No migration found for version '%s' with source_module '%s' and destination_module '%s' declared in module '%s'", $version, $data[1], $data[2], $data[0])); } } diff --git a/core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php b/core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php index 9dc9ffe3dafb..68acfc98f814 100644 --- a/core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php +++ b/core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php @@ -184,9 +184,9 @@ protected function readMultilingualContent($filename) { foreach ($translated_languages as $language) { if (file_exists($default_content_path . "$language/$filename") && ($handle = fopen($default_content_path . "$language/$filename", 'r')) !== FALSE) { - $header = fgetcsv($handle); + $header = fgetcsv($handle, escape: ''); $line_counter = 0; - while (($content = fgetcsv($handle)) !== FALSE) { + while (($content = fgetcsv($handle, escape: '')) !== FALSE) { $keyed_content[$language][$line_counter] = array_combine($header, $content); $line_counter++; } -- GitLab