prepend text node cause "head-content" shipped to <body>

VERIFIED INVALID

Status

()

Core
HTML: Parser
VERIFIED INVALID
6 years ago
6 years ago

People

(Reporter: gengyun, Unassigned)

Tracking

16 Branch
x86_64
Windows 7
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

6 years ago
User Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0E; .NET4.0C)

Steps to reproduce:

open any html page, if you write some text in front of the page such as:


some text here...
<html>
<head>
<meta>
<link>
...
</head>
<body>
...
</body>




Actual results:

everything in the <head> will be shipped out of head, and put under the <body> node like:
<html>
<head>
</head>
<body>
same text here...
<meta>
<link>
...
</body>
</html>


Expected results:

I think it's mainly because the fix to bug 307122. When the html-parser encountered some text, it will open a <body> and put the text in. It will also excute the following code line:

mFlags |= NS_DTD_FLAG_HAD_BODY

which will cause the parser thinks it has encountered a explict opened body, and the following code:

        theHeadIsParent = theHeadIsParent &&
          (isExclusive ||
           (prefersBody
            ? (mFlags & NS_DTD_FLAG_HAS_EXPLICIT_HEAD) &&
              (mFlags & NS_DTD_FLAG_HAS_OPEN_HEAD)
            : !(mFlags & NS_DTD_FLAG_HAS_MAIN_CONTAINER)));

will end up with theHeadIsParent = false;

So any head-content such as <link> and <meta> will be misplaced. I think a quick fix should put them to the right place.
Component: Untriaged → HTML: Parser
Product: Firefox → Core
(In reply to gengyun from comment #0)

> Actual results:
> 
> everything in the <head> will be shipped out of head, and put under the
> <body> node like:
> <html>
> <head>
> </head>
> <body>
> same text here...
> <meta>
> <link>
> ...
> </body>
> </html>

This behavior is required by the HTML specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construction.html

> mFlags |= NS_DTD_FLAG_HAD_BODY

That code is no longer in use for parsing anything other than about:blank.

Marking INVALID in the sense that this is not a bug. Bugzilla lacks a better resolution semantic between INVALID and WONTFIX.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → INVALID
(Reporter)

Comment 2

6 years ago
Thanks, now I understand much better!
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.