Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 d48db1f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions test/unit/selector.js
Expand Up @@ -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"] );
Expand Down

4 comments on commit d48db1f

@jdalton
Copy link
Member

@jdalton jdalton commented on d48db1f Sep 2, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member Author

@jeresig jeresig commented on d48db1f Sep 2, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

@jdalton jdalton commented on d48db1f Sep 2, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

@dperini dperini commented on d48db1f Sep 2, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.