use ternary

pull/5701/head
Ben McCann 4 years ago
parent 30df740729
commit 88e2146701

@ -72,12 +72,6 @@ export function merge_ssr_styles(style_attribute, style_directive) {
const ATTR_REGEX = /[&"]/g; const ATTR_REGEX = /[&"]/g;
const CONTENT_REGEX = /[&<]/g; const CONTENT_REGEX = /[&<]/g;
const escapes = {
'"': '&quot;',
'&': '&amp;',
'<': '&lt'
};
export function escape(html: string, is_attr = false) { export function escape(html: string, is_attr = false) {
if (typeof html !== 'string') return html; if (typeof html !== 'string') return html;
@ -89,7 +83,8 @@ export function escape(html: string, is_attr = false) {
while (pattern.test(html)) { while (pattern.test(html)) {
const i = pattern.lastIndex - 1; const i = pattern.lastIndex - 1;
escaped += html.slice(last, i) + escapes[html[i]]; const ch = html[i];
escaped += html.slice(last, i) + (ch === '&' ? '&amp;' : (ch === '"' ? '&quot;' : '&lt;'));
last = i + 1; last = i + 1;
} }

Loading…
Cancel
Save