Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unexpected special replacement pattern #293

Merged
merged 6 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cjs/html/text-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TextElement extends HTMLElement {

toString() {
const outerHTML = toString.call(this.cloneNode());
return outerHTML.replace(/></, `>${this.textContent}<`);
lawvs marked this conversation as resolved.
Show resolved Hide resolved
return outerHTML.replace('><', () => `>${this.textContent}<`);
}
}
exports.TextElement = TextElement
2 changes: 1 addition & 1 deletion esm/html/text-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export class TextElement extends HTMLElement {

toString() {
const outerHTML = toString.call(this.cloneNode());
return outerHTML.replace(/></, `>${this.textContent}<`);
lawvs marked this conversation as resolved.
Show resolved Hide resolved
return outerHTML.replace('><', () => `>${this.textContent}<`);
}
}
14 changes: 14 additions & 0 deletions test/html/script-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,17 @@ assert(head.firstChild.innerHTML, 'html`<p>ok</p>`;', '<script>.innerHTML');
script.type = 'text/javascript';
assert(script.type, 'text/javascript', '<script>.type');
}

{
// https://github.com/WebReflection/linkedom/issues/292
const { document } = parseHTML('<html></html>');
const script = document.createElement('script')
script.innerHTML = 'const test = "$$ $& $1"'
document.head.append(script)
assert(document.toString(), '<html><head><script>const test = "$$ $& $1"</script></head></html>')
}

{
const { document } = parseHTML('<html><script>const test = "$$ $& $1"</script></html>');
assert(document.toString(), '<html><script>const test = "$$ $& $1"</script></html>')
}
2 changes: 1 addition & 1 deletion worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8567,7 +8567,7 @@ class TextElement extends HTMLElement {

toString() {
const outerHTML = toString.call(this.cloneNode());
return outerHTML.replace(/></, `>${this.textContent}<`);
lawvs marked this conversation as resolved.
Show resolved Hide resolved
return outerHTML.replace('><', () => `>${this.textContent}<`);
}
}

Expand Down
Loading