From cd88a3a74a001ccbf5af691924909a92b6e753db Mon Sep 17 00:00:00 2001 From: teidesu <86301490+teidesu@users.noreply.github.com> Date: Sun, 5 Jun 2022 23:53:59 +0300 Subject: [PATCH] feat(parser): automatically escape attributes in template strings --- packages/html-parser/src/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/html-parser/src/index.ts b/packages/html-parser/src/index.ts index f9d59770..9e4dbc75 100644 --- a/packages/html-parser/src/index.ts +++ b/packages/html-parser/src/index.ts @@ -26,8 +26,12 @@ export function html( sub.forEach((it, idx) => { if (typeof it === 'boolean' || !it) return - if (typeof it === 'string') it = HtmlMessageEntityParser.escape(it) - else { + if (typeof it === 'string') { + it = HtmlMessageEntityParser.escape( + it, + !!str.match(/=['"]$/) + ) + } else { if (it.mode && it.mode !== 'html') throw new Error(`Incompatible parse mode: ${it.mode}`) it = it.value