Skip to content

Commit 2a66812

Browse files
committed
[FEATURE] Do not escape characters that do not need escaping in CSS string
1 parent f724347 commit 2a66812

1 file changed

Lines changed: 3 additions & 21 deletions

File tree

src/Value/CSSString.php

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,28 +97,10 @@ public function render(OutputFormat $outputFormat): string
9797

9898
private function escape(string $str, string $quote) : string
9999
{
100-
$matches = [
101-
0x0, // null
102-
0x5c, // \
103-
];
100+
$str = \addslashes($str);
104101

105-
$matches[] = $quote === '"' ? 0x22 : 0x27;
102+
$replace = $quote === '"' ? ["\\'" => "'"] : ["\\\"" => "\""];
106103

107-
$length = \strlen($str);
108-
$output = '';
109-
$previous = 0x0;
110-
111-
for ($i = 0; $i < $length; ++$i) {
112-
$current = \ord($str[$i]);
113-
114-
if (\in_array($current, $matches, true) && $previous !== 0x5c) {
115-
$output .= '\\';
116-
}
117-
118-
$output .= $str[$i];
119-
$previous = $current;
120-
}
121-
122-
return $output;
104+
return \str_replace(array_keys($replace), array_values($replace), $str);
123105
}
124106
}

0 commit comments

Comments
 (0)