diff --git a/src/utils/html.ts b/src/utils/html.ts index 5e9ff918..557945dd 100644 --- a/src/utils/html.ts +++ b/src/utils/html.ts @@ -1,3 +1,5 @@ +import { escape } from 'entities'; + interface RawHtml { raw: true; contents: string; @@ -10,16 +12,6 @@ interface RawHtmlOptions { joiner?: string; } -export function escape(str: string) { - if (!str) return ''; - - return str.replace(/&/g, '&') - .replace(//g, '>') - .replace(/"/g, '"') - .replace(/'/g, '''); -} - /** * Prevent values from being escaped by html``. * @param val Any value. @@ -40,7 +32,7 @@ export function r(val: any, options?: RawHtmlOptions): RawHtml { * ``` * const unsafe = `oops `; * testing.innerHTML = html`foo bar baz ${unsafe}`; - * console.assert(testing === "foo bar baz oops%20%3Cscript%3Ealert%281%29%3C/script%3E"); + * console.assert(testing === "foo bar baz oops<script>alert(1)</script>"); * ``` */ export function html(strings: TemplateStringsArray, ...values: (string | number | RawHtml)[]) {