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

Spurious HTML comments in embedded scripts #759

Closed
fcapolini opened this issue Feb 16, 2023 · 2 comments
Closed

Spurious HTML comments in embedded scripts #759

fcapolini opened this issue Feb 16, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@fcapolini
Copy link
Contributor

Describe the bug

The content of <script> and <style> tags is parsed with the same logic used for all other tags, which considers <!--, <! and <? as HTML comment markers.

Because of that this fragment from highlight.js:

{className:"meta",begin:/<![a-z]/,end:/>/,contains:[t,i,l,c]}

is erroneously parsed and is then serialized as:

{className:"meta",begin:/<!--[a-z]/,end:/-->/,contains:[t,i,l,c]}

which breaks the script.

To Reproduce

	const window = new Window({
		settings: {
			disableJavaScriptFileLoading: true,
			disableJavaScriptEvaluation: true,
			disableCSSFileLoading: true,
			enableFileSystemHttpRequests: false
		}
	});
	const domParser = new window.DOMParser();

	const newDocument = domParser.parseFromString(
		`<html>
			<body>
				<script>
					var test = {className:"meta",begin:/<![a-z]/,end:/>/,contains:[t,i,l,c]};
				</script>
			</body>
		</html>`,
		'text/html'
	);

	const output = new XMLSerializer().serializeToString(newDocument);
	// Spurious comment `<!--[a-z]/,end:/-->` appears in output markup

Expected behavior

In the test code above, the output should preserve the original JS code.

@fcapolini fcapolini added the bug Something isn't working label Feb 16, 2023
fcapolini added a commit to fcapolini/happy-dom that referenced this issue Feb 16, 2023
fcapolini added a commit to fcapolini/happy-dom that referenced this issue Feb 17, 2023
fcapolini added a commit to fcapolini/happy-dom that referenced this issue Feb 17, 2023
capricorn86 added a commit that referenced this issue Feb 17, 2023
…ded-scripts

#759@patch: Spurious HTML comments in embedded scripts.
@capricorn86
Copy link
Owner

capricorn86 commented Feb 17, 2023

Thanks again for your contribution @fcapolini! ⭐

Your fix has been released.

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v8.4.4

@fcapolini
Copy link
Contributor Author

Perfect, thanks to you! Super quick 💯

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