Closed Bug 815662 Opened 12 years ago Closed 11 years ago

querySelectorAll fails to throw an error on invalid selector syntax

Categories

(Core :: CSS Parsing and Computation, defect)

17 Branch
x86_64
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: dave.methvin, Unassigned)

References

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11 Steps to reproduce: document.querySelectorAll(":not(.red") //note missing closing paren http://jsfiddle.net/JhvqV/1/ Actual results: This selector works and returns all elements without class "red". Expected results: An invalid selector should throw a syntax error exception.
Component: Untriaged → DOM
Product: Firefox → Core
Our behavior is an immediate consequence of applying the CSS end-of-file parsing rules, which include implying any ')' that's needed. Note that this happens on the tokenizer level, so after tokenization the string provided matches the selectors grammar. Last I checked, WebKit doesn't implement those rules correctly, which is why you're seeing a different behavior there...
I agree it looks *very* explicit in the CSS2 spec, http://www.w3.org/TR/CSS21/syndata.html#parsing-errors says "User agents must close all open constructs (for example: blocks, parentheses, brackets, rules, strings, and comments) at the end of the style sheet." By that measure Firefox is doing the right thing, as are Opera and Internet Explorer. Safari and Chrome throw an error. The CSS3 syntax WD is a mess and I can't tell what it is trying to say, other than it's attempting to explicitly allow future extensions. In particular, http://www.w3.org/TR/css3-syntax/#principles says "...if a brace closing a declaration block is not present, the declaration block must be ignored since the closing brace is required to satisfy this grammar." This seems to directly contradict the CSS2 rule above about closing blocks.
Yeah, the CSS3 syntax draft you linked to is 9 years old and very much incomplete. The current work on that stuff is http://dev.w3.org/csswg/css3-syntax/ which is still unclear to the point of uselessness on this. Tab is going to define a separate selector parser at some point that querySelector can use, but it hasn't happened yet.
Component: DOM → Style System (CSS)
The 2003 draft of CSS3 Syntax should definitely be ignored. Look either at CSS 2.1 or the new Syntax draft: http://dev.w3.org/csswg/css-syntax/ In both cases, the EOF handling rules make this selector valid, as Boris said. Selectors 4 is expected to be defined on top of the CSS tokenizer.
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.