Skip to content
Permalink
Browse files

Remove cases of :contains() where quotes are used - not using quotes …

…follows more closely with the CSS Selector recommendation.
  • Loading branch information...
jeresig committed Sep 2, 2010
1 parent 8d04ffe commit d48db1f440a76ca2396d2217aac010ff7d515517
Showing with 6 additions and 5 deletions.
  1. +6 −5 test/unit/selector.js
@@ -326,18 +326,19 @@ test("pseudo - misc", function() {
t( "Headers", ":header", ["qunit-header", "qunit-banner", "qunit-userAgent"] );
t( "Has Children - :has()", "p:has(a)", ["firstp","ap","en","sap"] );

t( "Text Contains", "a:contains('Google')", ["google","groups"] );
t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
t( "Text Contains", "a:contains(Google)", ["google","groups"] );
t( "Text Contains", "a:contains(Google Groups)", ["groups"] );

t( "Text Contains", "a:contains('Google Groups (Link)')", ["groups"] );
t( "Text Contains", "a:contains('(Link)')", ["groups"] );
t( "Text Contains", "a:contains(Google Groups (Link))", ["groups"] );
t( "Text Contains", "a:contains((Link))", ["groups"] );
});


test("pseudo - :not", function() {
expect(24);
t( "Not", "a.blog:not(.link)", ["mark"] );
t( "Not - multiple", "#form option:not(:contains('Nothing'),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d", "option3e"] );

t( "Not - multiple", "#form option:not(:contains(Nothing),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d", "option3e"] );
t( "Not - recursive", "#form option:not(:not(:selected))[id^='option3']", [ "option3b", "option3c"] );

t( ":not() failing interior", "p:not(.foo)", ["firstp","ap","sndp","en","sap","first"] );

4 comments on commit d48db1f

@jdalton

This comment has been minimized.

Copy link
Member

replied Sep 2, 2010

Which recommendation is that? I found this old thing:
http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#content-selectors

The argument of this pseudo-class can be a string (surrounded by double quotes) or a keyword.

@jeresig

This comment has been minimized.

Copy link
Member Author

replied Sep 2, 2010

Ah - that's the old one that never made it to recommendation. As far as I'm able to determine all other pseudo-classes (as they call them) don't allow quotes inside the (...). I think it's pretty safe since this is a custom selector and at this point we at least try to get into the current convention style (of not using quotes). I'm referring to the current recommendation here: http://www.w3.org/TR/css3-selectors/

@jdalton

This comment has been minimized.

Copy link
Member

replied Sep 2, 2010

Well some allow identifiers, like :lang, with no quotes but they are different than strings and would require proper escaping for spaces and things. I think the old link has it correct as contains() should be treated like the attribute selector and allow strings, single or double quoted, as its purpose isn't really for identifiers.

@dperini

This comment has been minimized.

Copy link

replied Sep 2, 2010

jeresig,
quoted, unquoted, identifier, string ... this is not just related to ':contains()' pseudo-class (which never made in the specifications) it is a more general misunderstanding of the specifications through all jQuery/Sizzle selectors code, @jdalton correctly points out some of these.
The specifications you are pointing to explicitly states:
Attribute values must be CSS identifiers or strings. [CSS21] The case-sensitivity of attribute names and values in selectors depends on the document language.
you can read there what an "identifier" and what a "string" are in CSS selectors, this points back to CSS21 syntax rules so quite old and stable).
"strings" can be defined so only if they are quoted (single or double), unquoted strings do not exists, in that case they (maybe) are "identifiers".
"identifiers" syntax is different, it only allows certain range of characters and the start char must be "-?[a-zA-Z]" (can be escaped etc...).

Since you are pointing there with specs at hand, another minor problem is related to the currently allowed Unicode char range in jQuery/Sizzle.
As for specifications you linked to, the correct regular expression (for that Unicode part) is not [\u00c0-\uFFFF-] but [\u00A1-\uFFFF](all upper case or all lower case letters as you prefer, better not mix them for consistency).

Please sign in to comment.
You can’t perform that action at this time.