|
|
|
@ -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 = {
|
|
|
|
|
|
|
|
'"': '"',
|
|
|
|
|
|
|
|
'&': '&',
|
|
|
|
|
|
|
|
'<': '<'
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
@ -87,11 +81,12 @@ export function escape(html: string, is_attr = false) {
|
|
|
|
let escaped = '';
|
|
|
|
let escaped = '';
|
|
|
|
let last = 0;
|
|
|
|
let last = 0;
|
|
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
last = i + 1;
|
|
|
|
escaped += html.slice(last, i) + (ch === '&' ? '&' : (ch === '"' ? '"' : '<'));
|
|
|
|
}
|
|
|
|
last = i + 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return escaped + html.slice(last);
|
|
|
|
return escaped + html.slice(last);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|