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

DOM Comments don't align with HTML comments #1023

Closed
josepharhar opened this issue Oct 4, 2021 · 2 comments
Closed

DOM Comments don't align with HTML comments #1023

josepharhar opened this issue Oct 4, 2021 · 2 comments

Comments

@josepharhar
Copy link
Contributor

josepharhar commented Oct 4, 2021

In the HTML spec, it says that comments must not contain --> among other things: https://html.spec.whatwg.org/multipage/syntax.html#comments

In the DOM spec, it says that you can create a Comment with any text, no restrictions: https://dom.spec.whatwg.org/#interface-comment

This was raised in a chrome issue where someone pointed out that you can create a Comment in script which contains a -->, put other things after the -->, and reassign document.body.innerHTML = document.body.innerHTML which will make everything after the --> get parsed as actual HTML instead of comments

@mfreed7

@annevk
Copy link
Member

annevk commented Oct 5, 2021

It's generally true that you can create node trees that cannot be serialized or that can be serialized and then when parsed result in a different tree. This is not a unique ability of comments.

https://html.spec.whatwg.org/#serialising-html-fragments points this out in a warning.

https://html.spec.whatwg.org/#serialising-xhtml-fragments on the other hand does attempt to account for it, but I'm not sure how well tested that is.

Did you have a suggestion or do you think DOM should call this out more prominently?

@josepharhar
Copy link
Contributor Author

It's generally true that you can create node trees that cannot be serialized or that can be serialized and then when parsed result in a different tree. This is not a unique ability of comments.

With this in mind, I think it's OK to leave things as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants