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: [#1615] Fixes problems related to parsing <html>, <head> and <body> using DOMParser #1617

Conversation

capricorn86
Copy link
Owner

No description provided.

const newDocument = domParser.parseFromString(DOMParserSVG, 'image/svg+xml');
expect(new XMLSerializer().serializeToString(newDocument).replace(/[\s]/gm, '')).toBe(
DOMParserSVG.replace(/[\s]/gm, '')
);
});

Copy link
Contributor

@OlaviSau OlaviSau Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're planning on handling all the cases - then i suggest these as well:

export const DOMParserBODYSibling = '<body><example></example>Example Text</body><body></body>';
export const DOMParserBODYChildren = '<body><body></body><example></example>Example Text</body>';
it('recognises does not duplicate body when BODY is a child', () => {
	const newDocument = domParser.parseFromString(DOMParserBODYChildren, 'text/html');
	expect(newDocument.body.innerHTML).toBe('<example></example>Example Text');
});

it('recognises does not duplicate body when BODY is a sibling', () => {
	const newDocument = domParser.parseFromString(DOMParserBODYSibling, 'text/html');
	expect(newDocument.body.innerHTML).toBe('<example></example>Example Text');
});

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the test cases, thank you! 🙂

This turned out to be a lot more complicated than what I first thought and I had to refactor quite a bit of the logic, but I have hopefully covered all cases reported and discovered when reading the spec and tested in the browser.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's awesome though that you managed to get this through - impressive work :)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @OlaviSau!

@@ -128,11 +138,13 @@ export default <
},
col: {
className: 'HTMLTableColElement',
contentModel: HTMLElementConfigContentModelEnum.noDescendants
contentModel: HTMLElementConfigContentModelEnum.noDescendants,
permittedParents: ['colgroup']
},
colgroup: {
className: 'HTMLTableColElement',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class name is the same as the previous?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct.

If you run the following code in the browser you will see that both are using the HTMLTableColElement class:

// Outputs "HTMLTableColElement"
console.log(document.createElement('col').constructor.name);

// Outputs "HTMLTableColElement"
console.log(document.createElement('colgroup').constructor.name);

@capricorn86 capricorn86 merged commit ad3872d into master Dec 27, 2024
5 checks passed
@capricorn86 capricorn86 deleted the 1615-domparser-does-not-recognise-body-and-thus-creates-it-twice branch December 27, 2024 01:00
kakkokari-gtyih added a commit to misskey-dev/misskey that referenced this pull request Jan 24, 2025
changes due to capricorn86/happy-dom#1617 (XMLSerializer now produces valid XML)
kakkokari-gtyih added a commit to misskey-dev/misskey that referenced this pull request Jan 24, 2025
changes due to capricorn86/happy-dom#1617 (XMLSerializer now produces valid XML)
samunohito pushed a commit to misskey-dev/misskey that referenced this pull request Feb 15, 2025
* wip

* bump misskey-dev/eslint-plugin

* lint fixes (backend)

* lint fixes (frontend)

* lint fixes (frontend-embed)

* rollback nsfwjs to 4.2.0

ref: infinitered/nsfwjs#904

* rollback openapi-typescript to v6

v7でOpenAPIのバリデーションが入るようになった関係でスコープ外での変更が避けられないため一時的に戻した

* lint fixes (misskey-js)

* temporarily disable errored lint rule (frontend-shared)

* fix lint

* temporarily ignore errored file for lint (frontend-shared)

* rollback simplewebauthn/server to 12.0.0

v13 contains breaking changes that require some decision making

* lint fixes (frontend-shared)

* build misskey-js with types

* fix(backend): migrate simplewebauthn/server to v12

* fix(misskey-js/autogen): ignore indent rules to generate consistent output

* attempt to fix test

changes due to capricorn86/happy-dom#1617 (XMLSerializer now produces valid XML)

* attempt to fix test

changes due to capricorn86/happy-dom#1617 (XMLSerializer now produces valid XML)

* fix test

* fix test

* fix test

* Apply suggestions from code review

Co-authored-by: anatawa12 <anatawa12@icloud.com>

* bump summaly to v5.2.0

* update tabler-icons to v3.30.0-based

---------

Co-authored-by: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>
Co-authored-by: anatawa12 <anatawa12@icloud.com>
Ruruke pushed a commit to Ruruke/rukey that referenced this pull request Feb 15, 2025
* wip

* bump misskey-dev/eslint-plugin

* lint fixes (backend)

* lint fixes (frontend)

* lint fixes (frontend-embed)

* rollback nsfwjs to 4.2.0

ref: infinitered/nsfwjs#904

* rollback openapi-typescript to v6

v7でOpenAPIのバリデーションが入るようになった関係でスコープ外での変更が避けられないため一時的に戻した

* lint fixes (misskey-js)

* temporarily disable errored lint rule (frontend-shared)

* fix lint

* temporarily ignore errored file for lint (frontend-shared)

* rollback simplewebauthn/server to 12.0.0

v13 contains breaking changes that require some decision making

* lint fixes (frontend-shared)

* build misskey-js with types

* fix(backend): migrate simplewebauthn/server to v12

* fix(misskey-js/autogen): ignore indent rules to generate consistent output

* attempt to fix test

changes due to capricorn86/happy-dom#1617 (XMLSerializer now produces valid XML)

* attempt to fix test

changes due to capricorn86/happy-dom#1617 (XMLSerializer now produces valid XML)

* fix test

* fix test

* fix test

* Apply suggestions from code review

Co-authored-by: anatawa12 <anatawa12@icloud.com>

* bump summaly to v5.2.0

* update tabler-icons to v3.30.0-based

---------

Co-authored-by: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>
Co-authored-by: anatawa12 <anatawa12@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOMParser does not recognise BODY and thus creates it twice
2 participants