Last Comment Bug 12385 - CSS idents can't start with "-"
: CSS idents can't start with "-"
Status: RESOLVED INVALID
[css2.1] (see comment 23)
: css2, testcase
Product: Core
Classification: Components
Component: CSS Parsing and Computation (show other bugs)
: Trunk
: All All
: P3 normal (vote)
: Future
Assigned To: Nobody; OK to take it and work on it
:
Mentors:
http://www.editions-eyrolles.com/css2...
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 1999-08-24 08:58 PDT by David Baron :dbaron: ⌚️UTC+2 (mostly busy through August 4; review requests must explain patch)
Modified: 2007-07-31 20:01 PDT (History)
14 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
testcase (213 bytes, text/html)
2000-08-27 12:56 PDT, hidden
no flags Details

Description David Baron :dbaron: ⌚️UTC+2 (mostly busy through August 4; review requests must explain patch) 1999-08-24 08:58:15 PDT
DESCRIPTION:  CSS2 identifiers can't start with dash (0-9 and - are the
characters that can't start an identifier but can be in the middle).  I know
you're using -moz to begin identifiers that represent extensions, but (unless
this will be changed in CSS3), you shouldn't allow classes, etc., that begin
with a -.  That is:

.-d { font-weight: bold; }

should be ignored.

STEPS TO REPRODUCE:  Load above URL.

ACTUAL RESULTS: Fifth bulleted item has two words in bold.

EXPECTED RESULTS: Fifth bulleted item should not have any words in bold.

DOES NOT WORK CORRECTLY ON:
 * Linux, apprunner, 1999-08-20-13-M10
Comment 1 David Baron :dbaron: ⌚️UTC+2 (mostly busy through August 4; review requests must explain patch) 1999-08-24 16:29:59 PDT
ALSO DOES NOT WORK CORRECTLY ON:
 * Windows, apprunner, 1999-08-24-09-M10
Comment 2 Peter Linss 1999-08-24 17:25:59 PDT
CSS3 allows idents to start with dashes (explicitly to allow the extension
mechanism). Need to evaluate if this should apply to class names (and a few
other places where ident is allowed.
Comment 3 Christine Hoffman 1999-08-24 17:31:59 PDT
Verifying this LATER.
Comment 4 Pierre Saslawsky 1999-11-13 02:40:59 PST
Reassigning peterl's latered bugs to myself.
Comment 5 Christine Hoffman 1999-11-16 17:29:59 PST
Is this still latered? If not, please remove resolution. If not, I will verify
it again.
Comment 6 Pierre Saslawsky 1999-11-16 17:58:59 PST
Yep, still latered.

In case we (er... when we) look into it again, Ian posted some useful info about
errata to the CSS syntax under bug 18936.
Comment 7 Christine Hoffman 1999-11-17 10:55:59 PST
Verified LATER.
Comment 8 Hixie (not reading bugmail) 2000-01-13 16:00:59 PST
Migrating from {css1} to css1 keyword. The {css1}, {css2}, {css3} and {css-moz}
radars should now be considered deprecated in favour of keywords.
I am *really* sorry about the spam...
Comment 9 Hixie (not reading bugmail) 2000-06-07 14:01:51 PDT
Reopening and moving to Future...
Comment 10 Tobias Burnus 2000-08-05 08:21:42 PDT
I think it would be nice, if it would have an milestone (instead of Future)
assigned since Mozilla claims to support CSS fully.
See also:
http://www.w3.org/Style/CSS/Test/current/sec15.htm
and specs: http://www.w3.org/TR/REC-CSS2/syndata.html#q4
Comment 11 hidden 2000-08-27 12:56:42 PDT
Created attachment 13574 [details]
testcase
Comment 12 hidden 2000-08-27 12:57:37 PDT
added testcase
Comment 13 Kurt Weinschenker 2000-10-05 17:53:47 PDT
Tried http://www.w3.org/Style/CSS/Test/current/sec15.htm on Mac OS 9.0.4,
Mozilla build 2000100208-M18, still doesn't work.

(CSS1 Test Suite:  1.5 ID as selector)
Comment 14 Hixie (not reading bugmail) 2001-02-12 16:40:38 PST
Netscape's standard compliance QA team reorganised itself once again, so taking 
remaining non-tables style bugs. Sorry about the spam. I tried to get this done 
directly at the database level, but apparently that is "not easy because of the 
shadow db", "plus it screws up the audit trail", so no can do...
Comment 15 Daniel Glazman (:glazou) 2001-08-27 05:11:57 PDT
Changing URL to my test suite since my publisher modified its web site
architecture w/o notification :-(
Comment 16 David Baron :dbaron: ⌚️UTC+2 (mostly busy through August 4; review requests must explain patch) 2002-06-19 21:05:36 PDT
Assigning pierre's remaining Style System-related bugs to myself.
Comment 17 Boris Zbarsky [:bz] 2002-08-11 03:01:07 PDT
Has the WG decided anything here yet?
Comment 18 Karl Ove Hufthammer 2002-08-11 10:24:14 PDT
> Has the WG decided anything here yet?

I don't know, but they have at *not* allowed the
'-' character in the CSS 2.1 WD, released ~a week ago
<URL: http://www.w3.org/TR/2002/WD-CSS21-20020802/grammar.html >.
Comment 19 Boris Zbarsky [:bz] 2002-08-11 19:00:37 PDT
Yes... but this is not a CSS2 issue.  This is a question of what CSS3 will say
(since CSS2 also does not have the -vendor-ident mechanism in place).
Comment 20 Anne (:annevk) 2004-03-05 08:11:01 PST
CSS2.1 does: <http://www.w3.org/TR/2004/CR-CSS21-20040225/syndata.html#q4>
Comment 21 Boris Zbarsky [:bz] 2004-03-05 08:50:48 PST
Yeah, at this point this looks invalid.
Comment 22 David Baron :dbaron: ⌚️UTC+2 (mostly busy through August 4; review requests must explain patch) 2004-03-05 09:35:26 PST
"Only properties, values, units, pseudo-classes, pseudo-elements, and at-rules
may start with a hyphen (-); other identifiers (e.g. element names, classes, or
IDs) may not." (4.1.3)
Comment 23 Anne (:annevk) 2004-03-05 10:22:10 PST
To summarize: this is a valid bug, since Mozilla supports something it should
not support (.-d).
Comment 24 Justin Wood (:Callek) 2004-06-23 21:12:37 PDT
hmm iirc recently we had a problem with calendar class names (which started with
'-' 

iirc we warn about it in debug builds, perhaps we can make the warning into an
error?
Comment 25 Gérard Talbot 2007-06-25 12:29:27 PDT
Latest CSS 2.1 WD (06 November 2006) suggests that IDs can start with an hyphen (-) and then may be followed by an alphabetic character [A-Za-z] or may then even be followed by an underscore (_).

{
In CSS, identifiers  (including element names, classes, and IDs in selectors) can contain only the characters [a-z0-9] and ISO 10646 characters U+00A1 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, or a hyphen followed by a digit.
}
CSS 2.1, Working Draft 06 November 2006, Section 4.1.3 Characters and case
http://www.w3.org/TR/CSS21/syndata.html#q6

{
ident		-?{nmstart}{nmchar}*
nmstart		[_a-z]|{nonascii}|{escape}
}
CSS 2.1, Working Draft 06 November 2006, G.2 Lexical scanner
http://www.w3.org/TR/CSS21/grammar.html#q2

To make things worse,
CSS 2.1, Working Draft 06 November 2006, section G.3 Comparison of tokenization in CSS 2.1 and CSS1 at
http://www.w3.org/TR/CSS21/grammar.html#tokenizer-diffs
says 
{
In CSS1, a class name could start with a digit (".55ft")
}
while CSS 1 spec says
{
in CSS1, selectors (element names, classes and IDs) can contain only the characters A-Z, 0-9, and Unicode characters 161-255, plus dash (-); they cannot start with a dash or a digit;
}
http://www.w3.org/TR/REC-CSS1#css1-conformance

Finally, HTML 4.01 claims that
{
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by
any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons
(":"), and periods (".").
}
http://www.w3.org/TR/html4/types.html#type-id

Did I miss something? 
I'm voting for this bug :)
Comment 26 Gérard Talbot 2007-06-25 13:21:40 PDT
Example:
<p id="-asdf">

Both the HTML 4.01 spec and W3C HTML validator say this attribute value is invalid

but

#-asdf { color: red }
is fine and ok with latest CSS 2.1 WD and with the W3C CSS validator
Comment 27 Gérard Talbot 2007-06-26 11:58:28 PDT
Complete testcase for this bug:

http://www.gtalbot.org/BrowserBugsSection/MSIE7Bugs/CSS1ForwardCompatibleParsing.html
Comment 28 Boris Zbarsky [:bz] 2007-06-26 18:47:03 PDT
We pass that testcase, no?
Comment 29 Gérard Talbot 2007-06-27 10:52:33 PDT
If we meticulously follow and comply with the latest CSS 2.1 (6 nov. 2006) WD, then yes, we pass that testcase.


I wish all CSS 2.1 WD would not have introduced exceptions and unneeded complexity and just carried on with the CSS1 and simple 
"selectors (element names, classes and IDs) (...) can not start with dash or digit".
Those kind of new CSS 2.1 exceptions encourage and promote invalid markup code as invalid attribute specifications are to be honored nevertheless in CSS 2.1.
Comment 30 Ray Kiddy 2007-07-22 16:11:13 PDT
FYI: There is a CSS 2.1 test that fails that is, I believe, from this bug.

The source has:

  .one { color: green; background: white; }
  .-ident, .one { color: red; }

  .two { color: green; background: white; }
  #-ident, .two { color: red; }

In both cases, the text should be green, but it is red.

http://www.w3.org/Style/CSS/Test/CSS2.1/current/t040103-ident-03-c.htm

Looking at:
http://www.w3.org/Style/CSS/Test/CSS2.1/current/t040103-ident-00-c.htm
...
http://www.w3.org/Style/CSS/Test/CSS2.1/current/t040103-ident-13-c.htm

All the others pass.
Comment 31 Gérard Talbot 2007-07-23 12:58:42 PDT
Ray,

The previous and current/latest [July 19th 2007, CR] CSS 2.1 spec says:
"in CSS, identifiers  (including element names, classes, and IDs in selectors) can contain only the characters [a-z0-9] and ISO 10646 characters U+00A1 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, or a hyphen followed by a digit."
http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier

Also, current (and previous) CSS 2.1, Section 4.1.1 Tokenization
http://www.w3.org/TR/CSS21/syndata.html#tokenization
still gives
ident 	[-]?{nmstart}{nmchar}*
nmstart [_a-z]|{nonascii}|{escape}

So, they can start with an hyphen as long as their next character is not a digit. E.g.: 

1-
id="-_" 
#-_ {color: red;}
is perfectly valid CSS 2.1

2-
id="-foo"
#-foo {color: red;}
is perfectly valid CSS 2.1

3-
class="-bar"
.-bar {color: red;}
is also perfectly valid CSS 2.1

and so is -ident since "i" is not a digit.

This is the CSS validator report according to CSS 2.1 profile of the t040103-ident-03-c.htm webpage:
http://jigsaw.w3.org/css-validator/validator?uri=http%3A%2F%2Fwww.w3.org%2FStyle%2FCSS%2FTest%2FCSS2.1%2Fcurrent%2Ft040103-ident-03-c.htm&warning=2&profile=css21&usermedium=all

As far as I can see, both sentences in 
http://www.w3.org/Style/CSS/Test/CSS2.1/current/t040103-ident-03-c.htm
should be red, not green. That test needs to be updated.
Comment 32 Gérard Talbot 2007-07-23 13:20:34 PDT
As far as I'm concerned, 
- this bug should be resolved as WORKSFORME, 
- the summary should be updated so that we don't mislead bug reporters 
- I. Hickson should also be informed that one of his test 
CSS2.1/current/t040103-ident-03-c.htm
may not be correct.
Comment 33 fantasai 2007-07-31 20:01:28 PDT
The restriction on starting hyphens in identifiers was removed.
The resolution was for issue 167 in issues-3, in response to
  http://lists.w3.org/Archives/Public/www-style/2006Mar/0068.html
The discussion is minuted in
  http://lists.w3.org/Archives/Member/w3c-css-wg/2006JulSep/0006.html
where it basically says there's interop on supporting hyphens at the beginning of class names and the restriction is confusing anyway.

Marking INVALID.

Note You need to log in before you can comment on or make changes to this bug.