From 009376b274df2ebc50360cbedf29b2c6dcef7b2c Mon Sep 17 00:00:00 2001 From: Victor Solano Date: Fri, 16 Oct 2026 19:06:39 +0200 Subject: [PATCH 1/2] fix: keep text elements' content out of attribute values (#341) TextElement.toString() put the element text back at the first "><" of its childless clone, which can be inside an attribute value, so a style, script, title or textarea with such an attribute serialized its text into the attribute and an empty element body. The text now goes right before the end tag, the last "> --- cjs/html/text-element.js | 6 +++++- esm/html/text-element.js | 6 +++++- worker.js | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cjs/html/text-element.js b/cjs/html/text-element.js index d55b5d3c..4040718f 100644 --- a/cjs/html/text-element.js +++ b/cjs/html/text-element.js @@ -10,7 +10,11 @@ class TextElement extends HTMLElement { toString() { const outerHTML = toString.call(this.cloneNode()); - return outerHTML.replace('><', () => `>${this.textContent}<`); + // the text goes before the end tag: attribute values can contain "><" too + const end = outerHTML.lastIndexOf('><', () => `>${this.textContent}<`); + // the text goes before the end tag: attribute values can contain "><" too + const end = outerHTML.lastIndexOf('><', () => `>${this.textContent}<`); + // the text goes before the end tag: attribute values can contain "><" too + const end = outerHTML.lastIndexOf('> Date: Fri, 16 Oct 2026 19:16:05 +0200 Subject: [PATCH 2/2] fix: return a self-closed text element clone unchanged Check for the self-closing form first, so an attribute value with "> --- cjs/html/text-element.js | 6 +++--- esm/html/text-element.js | 6 +++--- worker.js | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cjs/html/text-element.js b/cjs/html/text-element.js index 4040718f..2dfe704c 100644 --- a/cjs/html/text-element.js +++ b/cjs/html/text-element.js @@ -10,10 +10,10 @@ class TextElement extends HTMLElement { toString() { const outerHTML = toString.call(this.cloneNode()); - // the text goes before the end tag: attribute values can contain "><" too - const end = outerHTML.lastIndexOf('>')) return outerHTML; // self-closed, as in XML documents + // the text goes before the end tag, as attribute values can contain "><" too - const end = outerHTML.lastIndexOf('>')) return outerHTML; // self-closed, as in XML documents + // the text goes before the end tag, as attribute values can contain "><" too - const end = outerHTML.lastIndexOf('>')) return outerHTML; // self-closed, as in XML documents + // the text goes before the end tag, as attribute values can contain ">