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

DOMParser parseFromString should not decode entities inside script tags #1530

Open
jrenjilian opened this issue Sep 4, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@jrenjilian
Copy link

Describe the bug
Script and style tags don't decode HTML entities, so myScript.textContent should contain < etc if present. This appears to work when creating a script element through document.createElement, but not when using new DOMParser().parseFromString.

To Reproduce

import { Window } from "happy-dom";

const window = new Window();

console.log(
  new window.DOMParser()
    .parseFromString(
      "<script>&lt;span&gt;Hello&lt;/span&gt;</script>",
      "text/html"
    )
    .querySelector("script")
    .textContent
);

// Result: <span>Hello</span>
// Expected: &lt;span&gt;Hello&lt;/span&gt;

(Running the above in a browser, skipping the happy-dom setup, gives the expected result)

Expected behavior
HTML entities are not decoded by textContent when used inside a script tag in new DOMParser().parseFromString.

Device:

  • OS: macOS 14.6.1
  • Browser: N/A
  • Version: happy-dom 15.7.3, also tried 14.12.3 which had the same issue; Node 22.2.0

Additional context
I ran into this when embedding data containing HTML entities into documents with <script type="application/json">.

@jrenjilian jrenjilian added the bug Something isn't working label Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant