Skip to content

Commit ae4c5af

Browse files
authored
[CLEANUP] Refactor and enhance CSSString::escape() (#1467)
Fixes #1466
1 parent b36a6ac commit ae4c5af

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/Value/CSSString.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ public function getString(): string
9393
*/
9494
public function render(OutputFormat $outputFormat): string
9595
{
96-
$string = $this->escape($this->string, $outputFormat->getStringQuotingType());
97-
$string = \str_replace("\n", '\\A', $string);
98-
return $outputFormat->getStringQuotingType() . $string . $outputFormat->getStringQuotingType();
96+
return $outputFormat->getStringQuotingType()
97+
. $this->escape($this->string, $outputFormat)
98+
. $outputFormat->getStringQuotingType();
9999
}
100100

101101
/**
@@ -112,14 +112,14 @@ public function getArrayRepresentation(): array
112112
];
113113
}
114114

115-
/**
116-
* @param "'"|'"' $quote
117-
*/
118-
private function escape(string $string, string $quote): string
115+
private function escape(string $string, OutputFormat $outputFormat): string
119116
{
120117
$charactersToEscape = '\\';
121-
$charactersToEscape .= ($quote === '"' ? '"' : "'");
118+
$charactersToEscape .= ($outputFormat->getStringQuotingType() === '"' ? '"' : "'");
119+
$withEscapedQuotes = \addcslashes($string, $charactersToEscape);
120+
121+
$withNewlineEncoded = \str_replace("\n", '\\A', $withEscapedQuotes);
122122

123-
return \addcslashes($string, $charactersToEscape);
123+
return $withNewlineEncoded;
124124
}
125125
}

0 commit comments

Comments
 (0)