Closed Bug 1501642 Opened 7 years ago Closed 7 years ago

DOMParser processes HTML tags inside CSS comments

Categories

(Core :: DOM: Core & HTML, defect)

63 Branch
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: webmaster, Unassigned)

Details

Attachments

(1 file)

Attached file DOMParserBug.html
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0 Steps to reproduce: Load the attached HTML file into the browser. The embedded script calls DOMParser with HTML containing a style sheet definition. The style sheet has a </style> end tag in a comment. Actual results: The </style> end tag within the comment prematurely terminated parsing of the style sheet so the alert box shows 'Number of rules: 1' Expected results: The alert box should show 'Number of rules: 2'
Reproducible. Build ID 20181029100347 User Agent Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0 I go a little bit further and tested it in Chrome and IE Google Chrome: did not show up anything IE: Same outcome as in Firefox.
Status: UNCONFIRMED → NEW
Component: Untriaged → Layout
Ever confirmed: true
Product: Firefox → Core
(In reply to Andrew Jarvis from comment #0) > Expected results: > > The alert box should show 'Number of rules: 2' What spec says that? Firefox / Edge looks correct to me, I don't know why the HTML parser would need to know CSS comment syntax. Blink / WebKit also agrees on just one style sheet, just doesn't let you access it via document.styleSheets, which I guess is wrong. HTML-parsing wise all browsers seem consistent, so I'm pretty sure this is invalid, but I've cc'd some folks that can correct me if I'm wrong.
Status: NEW → RESOLVED
Closed: 7 years ago
Component: Layout → DOM: Core & HTML
Resolution: --- → INVALID
You're not wrong. </style> terminates <style>. That determination happens before any parsing of the sheet even starts. The string determined by that is then passed to the CSS parser.
FWIW, this behavior is well-specced in the HTML spec: https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments It clearly shows that HTML parser would treat content inside <style> as raw text, and ends it whenever </style> is found.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: