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 outputting improper HTML (attributes do not keep necessary entities) #944

Open
vknowles-rv opened this issue May 31, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@vknowles-rv
Copy link

Describe the bug
parseFromString improperly handling html entities. I believe it stems from changes via #908. parseFromString is working as expected in version 9.15. If outerHTML is used via happy-dom after a parse, it will output improper HTML (ex. <ul data-obj="{"missUseOfQuotes":true}"></ul>)

To Reproduce
Steps to reproduce the behavior:

let parser = new DOMParser();

parser.parseFromString('<ul data-obj="{&quot;id&quot;:&quot;8im09mactz8v3d8&quot;,&quot;type&quot;:&quot;html&quot;}"></ul>', 'text/html').body.outerHTML

Expected behavior
Chrome:

<body><ul data-obj="{&quot;id&quot;:&quot;8im09mactz8v3d8&quot;,&quot;type&quot;:&quot;html&quot;}"></ul></body>

happy-dom 9.15

<body><ul data-obj="{&quot;id&quot;:&quot;8im09mactz8v3d8&quot;,&quot;type&quot;:&quot;html&quot;}"></ul></body>

happy-dom latest

<body><ul data-obj="{"id":"8im09mactz8v3d8","type":"html"}"></ul></body>

Device:

  • OS: macOS Ventura
  • Browser: Node v16.20
  • Version [e.g. 22]

Additional context
I'm using happy dom via vitest.

@vknowles-rv vknowles-rv added the bug Something isn't working label May 31, 2023
@vknowles-rv vknowles-rv changed the title DOM Parser parseFromString outputting improper HTML (attributes do not keep necessary entities) DOMParser parseFromString outputting improper HTML (attributes do not keep necessary entities) May 31, 2023
@adaboese
Copy link

Is there a workaround?

@adaboese
Copy link

Can confirm that pinning v9.15 fixes my issue as well.

const window = new Window();

const document = new window.DOMParser().parseFromString(`<code>&lt;html&gt;</code>`, 'text/html');

document.documentElement.outerHTML

Expecting output to be <code>&lt;html&gt;</code>, but getting <code><html></code>

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

2 participants