Closed Bug 239079 Opened 21 years ago Closed 21 years ago

ID tokens starting with digit allowed by CSS scanner

Categories

(Core :: CSS Parsing and Computation, defect, P2)

defect

Tracking

()

RESOLVED FIXED
mozilla1.8alpha1

People

(Reporter: edumerco, Assigned: bzbarsky)

References

()

Details

Attachments

(1 file, 2 obsolete files)

User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.5) Gecko/20031007 Firebird/0.7 Build Identifier: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.5) Gecko/20031007 Firebird/0.7 div.600 { width: 600px; } Doesn't render in 600px wide. div#600 { width: 600px; } Works OK. Reproducible: Always Steps to Reproduce: 1. Create an HTML document with a <div class="600">. 2. Link to it a stylesheet with the selector/prop: div.600 {width: 600px; } 3. Watch the page. The div flows normally, and it is not 600px wide. 4. Change the <div class="600"> to <div id="600">. 5. Watch the page. Now the div in the document is 600 px wide. Actual Results: The div in the document is 600 px wide, asi it should be. Expected Results: Render the div block with 600 px width from the first attempt (with the CLASS selector). No crash.
A class or ID starting with a digit is invalid. http://www.w3.org/TR/2004/CR-CSS21-20040225/syndata.html#q6 You're probably writing a quirks-mode document where breaking that rule is allowed for backwards compatibility. Probably quirks mode allows it in IDs but not classes. A testcase or URL showing this problem would help.
Actually, this is a problem in both modes. The code at http://lxr.mozilla.org/seamonkey/source/content/html/style/src/nsCSSScanner.cpp#485 doesn't check that the first char of the putative ID is a StartsIdent(). It probably should, but deferring to David on this one, since syntax is his thing...
Assignee: nobody → dbaron
Status: UNCONFIRMED → NEW
Component: Layout: Block and Inline → Style System (CSS)
Ever confirmed: true
QA Contact: core.layout.block-and-inline → ian
Summary: ignores width properties with CLASS selector, works OK with ID selector → ID tokens starting with digit allowed by CSS scanner
Attached patch So like this, I guess (obsolete) — Splinter Review
Attachment #145301 - Flags: superreview?(dbaron)
Attachment #145301 - Flags: review?(dbaron)
Comment on attachment 145301 [details] [diff] [review] So like this, I guess No, it should still tokenize as ID (which should probably be HASH), it should shouldn't parse as an ID selector. Doesn't this patch break colors?
Attachment #145301 - Flags: superreview?(dbaron)
Attachment #145301 - Flags: superreview-
Attachment #145301 - Flags: review?(dbaron)
Attachment #145301 - Flags: review-
Er, yes. Thinko... yes, a better name would help. ;) Taking.
Assignee: dbaron → bzbarsky
OS: Windows 98 → All
Priority: -- → P2
Hardware: PC → All
Target Milestone: --- → mozilla1.8alpha
Attached patch So more like this.... (obsolete) — Splinter Review
Comment on attachment 145304 [details] [diff] [review] So more like this.... I preferred this approach to duplicating the logic in nsCSSParser, but I could do that too, I guess.
Attachment #145304 - Flags: superreview?
Attachment #145304 - Flags: review?
Comment on attachment 145304 [details] [diff] [review] So more like this.... One other option is to make the scanner produce either HASH or ID tokens depending on whether the thing following '#' is an ident and then change color parsing to work with both token types while leaving id parsing to only work with the ID token.
(While you're at it should we remove IS_LATIN1? It doesn't seem to ever be used, and it seems useless... Then again, what would I know!)
Yeah, that can probably go.
Comment on attachment 145304 [details] [diff] [review] So more like this.... I totally failed to set those flags right... David, see comment 8
Attachment #145304 - Flags: superreview?(dbaron)
Attachment #145304 - Flags: superreview?
Attachment #145304 - Flags: review?(dbaron)
Attachment #145304 - Flags: review?
Attachment #145304 - Flags: superreview?(dbaron)
Attachment #145304 - Flags: superreview+
Attachment #145304 - Flags: review?(dbaron)
Attachment #145304 - Flags: review+
Attachment #145301 - Attachment is obsolete: true
Attachment #145304 - Attachment is obsolete: true
Comment on attachment 145374 [details] [diff] [review] Same without IS_LATIN1 Could this be approved for 1.7? This fixes a bug in our ID selector parsing in CSS (we're allowing invalid selectors).
Attachment #145374 - Flags: approval1.7?
Comment on attachment 145374 [details] [diff] [review] Same without IS_LATIN1 a=chofmann for 1.7
Attachment #145374 - Flags: approval1.7? → approval1.7+
Checked in, though I had to check in a DEBUG bustage fix as well as a Windows one (can't init static members at the declaration point in MSVC). Note that the fix is that now ID and class selectors act identically and do NOT apply the styles (as class selectors already did).
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
*** Bug 256684 has been marked as a duplicate of this bug. ***
This fix is actually incorrect; it should have happened before character escape processing, not after. See bug 299148.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: