From 063e6651ad7a20e9620abd922dd455e031a8f6de Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 19 Sep 2021 16:47:58 +0200 Subject: [PATCH] Fix to properly parse character references --- dev/lib/html.js | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/dev/lib/html.js b/dev/lib/html.js index a59e5cb..8955909 100644 --- a/dev/lib/html.js +++ b/dev/lib/html.js @@ -22,7 +22,7 @@ */ import assert from 'assert' -import {decodeEntity} from 'parse-entities/decode-entity.js' +import {parseEntities} from 'parse-entities' const own = {}.hasOwnProperty @@ -131,7 +131,7 @@ export function directiveHtml(options = {}) { /** @type {Attribute[]} */ // @ts-expect-error const attributes = this.getData('directiveAttributes') - attributes.push(['id', decodeLight(this.sliceSerialize(token))]) + attributes.push(['id', parseEntities(this.sliceSerialize(token))]) } /** @type {_Handle} */ @@ -140,7 +140,7 @@ export function directiveHtml(options = {}) { // @ts-expect-error const attributes = this.getData('directiveAttributes') - attributes.push(['class', decodeLight(this.sliceSerialize(token))]) + attributes.push(['class', parseEntities(this.sliceSerialize(token))]) } /** @type {_Handle} */ @@ -159,7 +159,7 @@ export function directiveHtml(options = {}) { /** @type {Attribute[]} */ // @ts-expect-error const attributes = this.getData('directiveAttributes') - attributes[attributes.length - 1][1] = decodeLight( + attributes[attributes.length - 1][1] = parseEntities( this.sliceSerialize(token) ) } @@ -240,23 +240,3 @@ export function directiveHtml(options = {}) { } } } - -/** - * @param {string} value - * @returns {string} - */ -function decodeLight(value) { - return value.replace( - /&(#(\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi, - decodeIfPossible - ) -} - -/** - * @param {string} $0 - * @param {string} $1 - * @returns {string} - */ -function decodeIfPossible($0, $1) { - return decodeEntity($1) || $0 -}