From 8caea2cf9bde9cf204ec6cf1e76bd39aba7de538 Mon Sep 17 00:00:00 2001
From: Dave Long <dave@longwaveconsulting.com>
Date: Sun, 19 Feb 2023 12:23:03 +0000
Subject: [PATCH] Issue #3328694 by murilohp, rpayanm, jonathan1055, xjm,
 cilefen: Incorrect sprintf parameter usage

(cherry picked from commit 465482a5718495b253d138aba2ba2b05d3402dbf)
---
 core/modules/file/src/FileRepository.php                  | 6 +++---
 core/modules/file/tests/src/Kernel/CopyTest.php           | 1 +
 core/modules/file/tests/src/Kernel/FileRepositoryTest.php | 1 +
 core/modules/file/tests/src/Kernel/MoveTest.php           | 1 +
 4 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/core/modules/file/src/FileRepository.php b/core/modules/file/src/FileRepository.php
index 3ec359c61db7..1a2d08d75af1 100644
--- a/core/modules/file/src/FileRepository.php
+++ b/core/modules/file/src/FileRepository.php
@@ -88,7 +88,7 @@ public function __construct(FileSystemInterface $fileSystem, StreamWrapperManage
    */
   public function writeData(string $data, string $destination, int $replace = FileSystemInterface::EXISTS_RENAME): FileInterface {
     if (!$this->streamWrapperManager->isValidUri($destination)) {
-      throw new InvalidStreamWrapperException(sprintf('Invalid stream wrapper: %destination', ['%destination' => $destination]));
+      throw new InvalidStreamWrapperException("Invalid stream wrapper: {$destination}");
     }
     $uri = $this->fileSystem->saveData($data, $destination, $replace);
     return $this->createOrUpdate($uri, $destination, $replace === FileSystemInterface::EXISTS_RENAME);
@@ -132,7 +132,7 @@ protected function createOrUpdate(string $uri, string $destination, bool $rename
    */
   public function copy(FileInterface $source, string $destination, int $replace = FileSystemInterface::EXISTS_RENAME): FileInterface {
     if (!$this->streamWrapperManager->isValidUri($destination)) {
-      throw new InvalidStreamWrapperException(sprintf('Invalid stream wrapper: %destination', ['%destination' => $destination]));
+      throw new InvalidStreamWrapperException("Invalid stream wrapper: {$destination}");
     }
     $uri = $this->fileSystem->copy($source->getFileUri(), $destination, $replace);
 
@@ -166,7 +166,7 @@ public function copy(FileInterface $source, string $destination, int $replace =
    */
   public function move(FileInterface $source, string $destination, int $replace = FileSystemInterface::EXISTS_RENAME): FileInterface {
     if (!$this->streamWrapperManager->isValidUri($destination)) {
-      throw new InvalidStreamWrapperException(sprintf('Invalid stream wrapper: %destination', ['%destination' => $destination]));
+      throw new InvalidStreamWrapperException("Invalid stream wrapper: {$destination}");
     }
     $uri = $this->fileSystem->move($source->getFileUri(), $destination, $replace);
     $delete_source = FALSE;
diff --git a/core/modules/file/tests/src/Kernel/CopyTest.php b/core/modules/file/tests/src/Kernel/CopyTest.php
index 668f99ae4089..9c8e79766b79 100644
--- a/core/modules/file/tests/src/Kernel/CopyTest.php
+++ b/core/modules/file/tests/src/Kernel/CopyTest.php
@@ -185,6 +185,7 @@ public function testExistingError() {
    */
   public function testInvalidStreamWrapper() {
     $this->expectException(InvalidStreamWrapperException::class);
+    $this->expectExceptionMessage('Invalid stream wrapper: foo://');
     $source = $this->createFile();
     $this->fileRepository->copy($source, 'foo://');
   }
diff --git a/core/modules/file/tests/src/Kernel/FileRepositoryTest.php b/core/modules/file/tests/src/Kernel/FileRepositoryTest.php
index 7db4dd08b9fc..b7790a659c49 100644
--- a/core/modules/file/tests/src/Kernel/FileRepositoryTest.php
+++ b/core/modules/file/tests/src/Kernel/FileRepositoryTest.php
@@ -170,6 +170,7 @@ public function testExistingError() {
    */
   public function testInvalidStreamWrapper() {
     $this->expectException(InvalidStreamWrapperException::class);
+    $this->expectExceptionMessage('Invalid stream wrapper: foo://');
     $this->fileRepository->writeData('asdf', 'foo://');
   }
 
diff --git a/core/modules/file/tests/src/Kernel/MoveTest.php b/core/modules/file/tests/src/Kernel/MoveTest.php
index 389b86210fe6..c48ed721cd09 100644
--- a/core/modules/file/tests/src/Kernel/MoveTest.php
+++ b/core/modules/file/tests/src/Kernel/MoveTest.php
@@ -209,6 +209,7 @@ public function testExistingError() {
    */
   public function testInvalidStreamWrapper() {
     $this->expectException(InvalidStreamWrapperException::class);
+    $this->expectExceptionMessage('Invalid stream wrapper: foo://');
     $source = $this->createFile();
     $this->fileRepository->move($source, 'foo://');
   }
-- 
GitLab