From 5d857ed0ba1303cb11a5777cd9759f91f9f46c1c Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 18 Jan 2026 15:39:17 +0100 Subject: [PATCH] [CLEANUP] Refactor and enhance `CSSString::escape()` Fixes #1466 --- src/Value/CSSString.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Value/CSSString.php b/src/Value/CSSString.php index c13906eb..8271671f 100644 --- a/src/Value/CSSString.php +++ b/src/Value/CSSString.php @@ -93,9 +93,9 @@ public function getString(): string */ public function render(OutputFormat $outputFormat): string { - $string = $this->escape($this->string, $outputFormat->getStringQuotingType()); - $string = \str_replace("\n", '\\A', $string); - return $outputFormat->getStringQuotingType() . $string . $outputFormat->getStringQuotingType(); + return $outputFormat->getStringQuotingType() + . $this->escape($this->string, $outputFormat) + . $outputFormat->getStringQuotingType(); } /** @@ -112,14 +112,14 @@ public function getArrayRepresentation(): array ]; } - /** - * @param "'"|'"' $quote - */ - private function escape(string $string, string $quote): string + private function escape(string $string, OutputFormat $outputFormat): string { $charactersToEscape = '\\'; - $charactersToEscape .= ($quote === '"' ? '"' : "'"); + $charactersToEscape .= ($outputFormat->getStringQuotingType() === '"' ? '"' : "'"); + $withEscapedQuotes = \addcslashes($string, $charactersToEscape); + + $withNewlineEncoded = \str_replace("\n", '\\A', $withEscapedQuotes); - return \addcslashes($string, $charactersToEscape); + return $withNewlineEncoded; } }