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; } }