/^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/i,
// Match: :even, :last-chlid, #id, .class
- /^([:.#]*)([\w\u0128-\uFFFF*-]+)/i
+ /^([:.#]*)((?:[\w\u0128-\uFFFF*-]|\\.)+)/i
],
token: [
} else {
// Optomize for the case nodeName#idName
- var re2 = /^(\w+)(#)([\w\u0128-\uFFFF*-]+)/i;
+ var re2 = /^(\w+)(#)((?:[\w\u0128-\uFFFF*-]|\\.)+)/i;
var m = re2.exec(t);
// Re-organize the results, so that they're consistent
} else {
// Otherwise, do a traditional filter check for
// ID, class, and element selectors
- re2 = /^([#.]?)([\w\u0128-\uFFFF*-]*)/i;
+ re2 = /^([#.]?)((?:[\w\u0128-\uFFFF*-]|\\.)*)/i;
m = re2.exec(t);
}
+ m[2] = m[2].replace(/\\/g, "");
+
var elem = ret[ret.length-1];
// Try to do a global search by ID, where we can
ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
} else {
- // Pre-compile a regular expression to handle class searches
- if ( m[1] == "." )
- var rec = new RegExp("(^|\\s)" + m[2] + "(\\s|$)");
-
// We need to find all descendant elements, it is more
// efficient to use getAll() when we are already further down
// the tree - we try to recognize that here
// It's faster to filter by class and be done with it
if ( m[1] == "." )
r = jQuery.grep( r, function(e) {
- return rec.test(e.className);
+ return jQuery.className.has(e, m[2]);
});
// Same with ID filtering
if ( jQuery.expr[ m[1] ]._resort )
m = jQuery.expr[ m[1] ]._resort( m );
+ m[2] = m[2].replace(/\\/g, "");
+
return false;
}
});
if ( m[1] == ":" && m[2] == "not" )
r = jQuery.filter(m[3], r, true).r;
- // Handle classes as a special case (this will help to
- // improve the speed, as the regexp will only be compiled once)
- else if ( m[1] == "." ) {
-
- var re = new RegExp("(^|\\s)" + m[2] + "(\\s|$)");
- r = jQuery.grep( r, function(e){
- return re.test(e.className || "");
- }, not);
-
// Otherwise, find the expression to execute
- } else {
+ else {
var f = jQuery.expr[m[1]];
if ( typeof f != "string" )
f = jQuery.expr[m[1]][m[2]];
});
test("id", function() {
- expect(17);
+ expect(23);
t( "ID Selector", "#body", ["body"] );
t( "ID Selector w/ Element", "body#body", ["body"] );
t( "ID Selector w/ Element", "ul#first", [] );
t( "Descendant ID selector using UTF8", "div #台北", ["台北"] );
t( "Child ID selector using UTF8", "form > #台北", ["台北"] );
+ t( "Escaped ID", "#foo\\:bar", ["foo:bar"] );
+ t( "Escaped ID", "#test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
+ t( "Descendant escaped ID", "div #foo\\:bar", ["foo:bar"] );
+ t( "Descendant escaped ID", "div #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
+ t( "Child escaped ID", "form > #foo\\:bar", ["foo:bar"] );
+ t( "Child escaped ID", "form > #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
+
t( "ID Selector, child ID present", "#form > #radio1", ["radio1"] ); // bug #267
t( "ID Selector, not an ancestor ID", "#form #first", [] );
t( "ID Selector, not a child ID", "#form > #option1a", [] );
});
test("class", function() {
- expect(10);
+ expect(16);
t( "Class Selector", ".blog", ["mark","simon"] );
t( "Class Selector", ".blog.link", ["simon"] );
t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
t( "Class selector using UTF8", ".台北Táiběi, .台北", ["utf8class1","utf8class2"] );
t( "Descendant class selector using UTF8", "div .台北Táiběi", ["utf8class1"] );
t( "Child class selector using UTF8", "form > .台北Táiběi", ["utf8class1"] );
+
+ t( "Escaped Class", ".foo\\:bar", ["foo:bar"] );
+ t( "Escaped Class", ".test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
+ t( "Descendant scaped Class", "div .foo\\:bar", ["foo:bar"] );
+ t( "Descendant scaped Class", "div .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
+ t( "Child escaped Class", "form > .foo\\:bar", ["foo:bar"] );
+ t( "Child escaped Class", "form > .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
});
test("multiple", function() {