Skip to content

Commit 6d96997

Browse files
committed
Optimize Handlebars::escapeExpression()
1 parent 105e2d7 commit 6d96997

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/Handlebars.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,14 @@ public static function template(string $templateSpec): \Closure
5252
*/
5353
public static function escapeExpression(string $string): string
5454
{
55-
$search = ['&', '<', '>', '"', "'", '`', '='];
56-
$replace = ['&amp;', '&lt;', '&gt;', '&quot;', '&#x27;', '&#x60;', '&#x3D;'];
57-
return str_replace($search, $replace, $string);
55+
return strtr($string, [
56+
'&' => '&amp;',
57+
'<' => '&lt;',
58+
'>' => '&gt;',
59+
'"' => '&quot;',
60+
"'" => '&#x27;',
61+
'`' => '&#x60;',
62+
'=' => '&#x3D;',
63+
]);
5864
}
5965
}

0 commit comments

Comments
 (0)