fix(html/codegen): Expand elements before which body isn’t elided (#8877)

**Description:**

For example, transforming `<body><noscript>` to `<noscript>` would
incorrectly change the meaning so `<noscript>` is parsed as a child of
`<head>`.

Reference: [§13.2.6.4.4 The "in head" insertion
mode](https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inhead),
[13.2.6.4.6 The "after head" insertion
mode](https://html.spec.whatwg.org/multipage/parsing.html#the-after-head-insertion-mode).

**Related issue:**

- Closes #8876.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg 2024-04-19 05:52:16 -07:00 committed by GitHub
parent a4d3b26217
commit 5419a9477f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 32 additions and 7 deletions

View File

@ -234,8 +234,7 @@ where
}
// A body element's start tag can be omitted if the element is empty, or if the
// first thing inside the body element is not ASCII whitespace or a comment, except
// if the first thing inside the body element is a meta, link, script, style, or
// template element.
// if the first thing inside the body element would be parsed differently outside.
"body"
if n.children.is_empty()
|| (match n.children.first() {
@ -253,14 +252,17 @@ where
})) if *namespace == Namespace::HTML
&& matches!(
&**tag_name,
"meta"
"base"
| "basefont"
| "bgsound"
| "frameset"
| "link"
| "meta"
| "noframes"
| "noscript"
| "script"
| "style"
| "template"
| "bgsound"
| "basefont"
| "base"
| "title"
) =>
{

View File

@ -0,0 +1,8 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Test</title>
</head>
<body><noscript>This app requires JavaScript.</noscript></body>
</html>

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Test</title>
</head>
<body><noscript>This app requires JavaScript.</noscript>
</body></html>

View File

@ -0,0 +1,6 @@
<!doctype html><html lang=en><head>
<meta charset=utf-8>
<title>Test</title>
</head>
<body><noscript>This app requires JavaScript.</noscript>

View File

@ -1,4 +1,4 @@
<!doctype html><html lang=en><meta charset=UTF-8><meta name=viewport content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title><noscript>
<!doctype html><html lang=en><meta charset=UTF-8><meta name=viewport content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title><body><noscript>
<a href=https://www.mozilla.com/>External Link</a>
</noscript>