Skip to content

Commit 5216400

Browse files
authored
fix: unexpected special replacement pattern (#293)
* fix: unexpected special replacement patterns * chore: add test * fix: other env * chore: follow code review * chore: tweak test * chore: replace with literal string for performance
1 parent a4d235b commit 5216400

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

cjs/html/text-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class TextElement extends HTMLElement {
1010

1111
toString() {
1212
const outerHTML = toString.call(this.cloneNode());
13-
return outerHTML.replace(/></, `>${this.textContent}<`);
13+
return outerHTML.replace('><', () => `>${this.textContent}<`);
1414
}
1515
}
1616
exports.TextElement = TextElement

esm/html/text-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export class TextElement extends HTMLElement {
99

1010
toString() {
1111
const outerHTML = toString.call(this.cloneNode());
12-
return outerHTML.replace(/></, `>${this.textContent}<`);
12+
return outerHTML.replace('><', () => `>${this.textContent}<`);
1313
}
1414
}

test/html/script-element.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,17 @@ assert(head.firstChild.innerHTML, 'html`<p>ok</p>`;', '<script>.innerHTML');
140140
script.type = 'text/javascript';
141141
assert(script.type, 'text/javascript', '<script>.type');
142142
}
143+
144+
{
145+
// https://github.com/WebReflection/linkedom/issues/292
146+
const { document } = parseHTML('<html></html>');
147+
const script = document.createElement('script')
148+
script.innerHTML = 'const test = "$$ $& $1"'
149+
document.head.append(script)
150+
assert(document.toString(), '<html><head><script>const test = "$$ $& $1"</script></head></html>')
151+
}
152+
153+
{
154+
const { document } = parseHTML('<html><script>const test = "$$ $& $1"</script></html>');
155+
assert(document.toString(), '<html><script>const test = "$$ $& $1"</script></html>')
156+
}

worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8567,7 +8567,7 @@ class TextElement extends HTMLElement {
85678567

85688568
toString() {
85698569
const outerHTML = toString.call(this.cloneNode());
8570-
return outerHTML.replace(/></, `>${this.textContent}<`);
8570+
return outerHTML.replace('><', () => `>${this.textContent}<`);
85718571
}
85728572
}
85738573

0 commit comments

Comments
 (0)