Skip to content

Commit 424500b

Browse files
committed
Make sure that +, >, ~ leading, rooted, selectors go to the old engine. Thanks to @rkatic for the catch! Fixes #7220.
1 parent 6bc3042 commit 424500b

File tree

3 files changed

+50
-83
lines changed

3 files changed

+50
-83
lines changed

src/sizzle-jquery.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,3 @@ jQuery.find = Sizzle;
22
jQuery.expr = Sizzle.selectors;
33
jQuery.expr[":"] = jQuery.expr.filters;
44
jQuery.unique = Sizzle.uniqueSort;
5-
jQuery.text = Sizzle.getText;
6-
jQuery.isXMLDoc = Sizzle.isXML;
7-
jQuery.contains = Sizzle.contains;

test/index.html

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ <h2 id="qunit-banner"></h2>
4848
<div id="qunit-testrunner-toolbar"></div>
4949
<h2 id="qunit-userAgent"></h2>
5050
<ol id="qunit-tests"></ol>
51-
51+
5252
<!-- Test HTML -->
5353
<div id="nothiddendiv" style="height:1px;background:white;" class="nothiddendiv">
5454
<div id="nothiddendivchild"></div>
5555
</div>
5656
<!-- this iframe is outside the #main so it won't reload constantly wasting time, but it means the tests must be "safe" and clean up after themselves -->
5757
<iframe id="loadediframe" name="loadediframe" style="display:none;" src="data/iframe.html"></iframe>
58-
<dl id="dl" style="position:absolute;top:-32767px;left:-32767px;">
59-
<div id="main">
58+
<dl id="dl" style="display:none;">
59+
<div id="main" style="display: none;">
6060
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
6161
<p id="ap">
62-
Here are some links in a normal paragraph: <a id="google" href="http://www.google.com/" title="Google!">Google</a>,
63-
<a id="groups" href="http://groups.google.com/" class="GROUPS">Google Groups (Link)</a>.
64-
This link has <code><a href="http://smin" id="anchor1">class="blog"</a></code>:
62+
Here are some links in a normal paragraph: <a id="google" href="http://www.google.com/" title="Google!">Google</a>,
63+
<a id="groups" href="http://groups.google.com/" class="GROUPS">Google Groups (Link)</a>.
64+
This link has <code><a href="http://smin" id="anchor1">class="blog"</a></code>:
6565
<a href="http://diveintomark.org/" class="blog" hreflang="en" id="mark">diveintomark</a>
6666

6767
</p>
@@ -87,14 +87,14 @@ <h2 id="qunit-userAgent"></h2>
8787

8888
<input type="hidden" name="hidden" id="hidden1"/>
8989
<input type="text" style="display:none;" name="foo[bar]" id="hidden2"/>
90-
90+
9191
<input type="text" id="name" name="name" value="name" />
9292
<input type="search" id="search" name="search" value="search" />
93-
93+
9494
<button id="button" name="button" type="button">Button</button>
95-
95+
9696
<textarea id="area1" maxlength="30">foobar</textarea>
97-
97+
9898
<select name="select1" id="select1">
9999
<option id="option1a" class="emptyopt" value="">Nothing</option>
100100
<option id="option1b" value="1">1</option>
@@ -114,33 +114,19 @@ <h2 id="qunit-userAgent"></h2>
114114
<option id="option3d" value="3">3</option>
115115
<option id="option3e">no value</option>
116116
</select>
117-
<select name="select4" id="select4" multiple="multiple">
118-
<optgroup disabled="disabled">
119-
<option id="option4a" class="emptyopt" value="">Nothing</option>
120-
<option id="option4b" disabled="disabled" selected="selected" value="1">1</option>
121-
<option id="option4c" selected="selected" value="2">2</option>
122-
</optgroup>
123-
<option selected="selected" disabled="disabled" id="option4d" value="3">3</option>
124-
<option id="option4e">no value</option>
125-
</select>
126-
<select name="select5" id="select5">
127-
<option id="option5a" value="3">1</option>
128-
<option id="option5b" value="2">2</option>
129-
<option id="option5c" value="1">3</option>
130-
</select>
131-
117+
132118
<object id="object1" codebase="stupid">
133119
<param name="p1" value="x1" />
134120
<param name="p2" value="x2" />
135121
</object>
136-
122+
137123
<span id="台北Táiběi"></span>
138124
<span id="台北" lang="中文"></span>
139125
<span id="utf8class1" class="台北Táiběi 台北"></span>
140126
<span id="utf8class2" class="台北"></span>
141127
<span id="foo:bar" class="foo:bar"></span>
142128
<span id="test.foo[5]bar" class="test.foo[5]bar"></span>
143-
129+
144130
<foo_bar id="foobar">test element</foo_bar>
145131
</form>
146132
<b id="floatTest">Float test.</b>
@@ -157,7 +143,7 @@ <h2 id="qunit-userAgent"></h2>
157143
<input name="types[]" id="types_anime" type="checkbox" value="anime" />
158144
<input name="types[]" id="types_movie" type="checkbox" value="movie" />
159145
</form>
160-
146+
161147
<form id="testForm" action="#" method="get">
162148
<textarea name="T3" rows="2" cols="15">?
163149
Z</textarea>
@@ -213,15 +199,15 @@ <h2 id="qunit-userAgent"></h2>
213199
<div><div class="hidden">hidden</div></div>
214200
</div>
215201
</div>
216-
202+
217203
<div id="tabindex-tests">
218204
<ol id="listWithTabIndex" tabindex="5">
219205
<li id="foodWithNegativeTabIndex" tabindex="-1">Rice</li>
220206
<li id="foodNoTabIndex">Beans</li>
221207
<li>Blinis</li>
222208
<li>Tofu</li>
223209
</ol>
224-
210+
225211
<div id="divWithNoTabIndex">I'm hungry. I should...</div>
226212
<span>...</span><a href="#" id="linkWithNoTabIndex">Eat lots of food</a><span>...</span> |
227213
<span>...</span><a href="#" id="linkWithTabIndex" tabindex="2">Eat a little food</a><span>...</span> |
@@ -230,7 +216,7 @@ <h2 id="qunit-userAgent"></h2>
230216
<span>...</span><a id="linkWithNoHrefWithTabIndex" tabindex="1">Eat some funyuns</a><span>...</span>
231217
<span>...</span><a id="linkWithNoHrefWithNegativeTabIndex" tabindex="-1">Eat some funyuns</a><span>...</span>
232218
</div>
233-
219+
234220
<div id="liveHandlerOrder">
235221
<span id="liveSpan1"><a href="#" id="liveLink1"></a></span>
236222
<span id="liveSpan2"><a href="#" id="liveLink2"></a></span>
@@ -246,26 +232,21 @@ <h2 id="qunit-userAgent"></h2>
246232
<div id="fx-queue" name="test">
247233
<div id="fadein" class='chain test' name='div'>fadeIn<div>fadeIn</div></div>
248234
<div id="fadeout" class='chain test out'>fadeOut<div>fadeOut</div></div>
249-
235+
250236
<div id="show" class='chain test'>show<div>show</div></div>
251237
<div id="hide" class='chain test out'>hide<div>hide</div></div>
252-
238+
253239
<div id="togglein" class='chain test'>togglein<div>togglein</div></div>
254240
<div id="toggleout" class='chain test out'>toggleout<div>toggleout</div></div>
255-
256-
241+
242+
257243
<div id="slideup" class='chain test'>slideUp<div>slideUp</div></div>
258244
<div id="slidedown" class='chain test out'>slideDown<div>slideDown</div></div>
259-
245+
260246
<div id="slidetogglein" class='chain test'>slideToggleIn<div>slideToggleIn</div></div>
261247
<div id="slidetoggleout" class='chain test out'>slideToggleOut<div>slideToggleOut</div></div>
262-
263-
<div id="fadetogglein" class='chain test'>fadeToggleIn<div>fadeToggleIn</div></div>
264-
<div id="fadetoggleout" class='chain test out'>fadeToggleOut<div>fadeToggleOut</div></div>
265-
266-
<div id="fadeto" class='chain test'>fadeTo<div>fadeTo</div></div>
267248
</div>
268-
249+
269250
<div id="fx-tests"></div>
270251
</div>
271252
</body>

test/unit/selector.js

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module("selector");
22

33
test("element", function() {
4-
expect(18);
5-
QUnit.reset();
4+
expect(19);
5+
reset();
66

77
ok( jQuery("*").size() >= 30, "Select all" );
88
var all = jQuery("*"), good = true;
@@ -21,13 +21,14 @@ test("element", function() {
2121
same( jQuery("p", jQuery("div")).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context." );
2222
same( jQuery("div").find("p").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context." );
2323

24-
same( jQuery("#form").find("select").get(), q("select1","select2","select3","select4","select5"), "Finding selects with a context." );
24+
same( jQuery("#form").find("select").get(), q("select1","select2","select3"), "Finding selects with a context." );
2525

2626
ok( jQuery("#length").length, '&lt;input name="length"&gt; cannot be found under IE, see #945' );
2727
ok( jQuery("#lengthtest input").length, '&lt;input name="length"&gt; cannot be found under IE, see #945' );
2828

2929
// Check for unique-ness and sort order
30-
same( jQuery("p, div p").get(), jQuery("p").get(), "Check for duplicates: p, div p" );
30+
same( jQuery("*").get(), jQuery("*, *").get(), "Check for duplicates: *, *" );
31+
same( jQuery("p").get(), jQuery("p, div p").get(), "Check for duplicates: p, div p" );
3132

3233
t( "Checking sort order", "h2, h1", ["qunit-header", "qunit-banner", "qunit-userAgent"] );
3334
t( "Checking sort order", "h2:first, h1:first", ["qunit-header", "qunit-banner"] );
@@ -36,7 +37,7 @@ test("element", function() {
3637

3738
if ( location.protocol != "file:" ) {
3839
test("XML Document Selectors", function() {
39-
expect(8);
40+
expect(7);
4041
stop();
4142
jQuery.get("data/with_fries.xml", function(xml) {
4243
equals( jQuery("foo_bar", xml).length, 1, "Element Selector with underscore" );
@@ -46,7 +47,6 @@ if ( location.protocol != "file:" ) {
4647
equals( jQuery("[name=prop2]", xml).length, 1, "Attribute selector with name" );
4748
equals( jQuery("#seite1", xml).length, 1, "Attribute selector with ID" );
4849
equals( jQuery("component#seite1", xml).length, 1, "Attribute selector with ID" );
49-
equals( jQuery("component", xml).filter("#seite1").length, 1, "Attribute selector filter with ID" );
5050
start();
5151
});
5252
});
@@ -154,7 +154,7 @@ test("class", function() {
154154
});
155155

156156
test("name", function() {
157-
expect(15);
157+
expect(14);
158158

159159
t( "Name selector", "input[name=action]", ["text1"] );
160160
t( "Name selector with single quotes", "input[name='action']", ["text1"] );
@@ -169,19 +169,13 @@ test("name", function() {
169169
same( jQuery("#form").find("input[name=action]").get(), q("text1"), "Name selector within the context of another element" );
170170
same( jQuery("#form").find("input[name='foo[bar]']").get(), q("hidden2"), "Name selector for grouped form element within the context of another element" );
171171

172-
var form = jQuery("<form><input name='id'/></form>").appendTo("body");
173-
174-
equals( form.find("input").length, 1, "Make sure that rooted queries on forms (with possible expandos) work." );
175-
176-
form.remove();
177-
178172
var a = jQuery('<div><a id="tName1ID" name="tName1">tName1 A</a><a id="tName2ID" name="tName2">tName2 A</a><div id="tName1">tName1 Div</div></div>').appendTo('#main').children();
179173

180174
equals( a.length, 3, "Make sure the right number of elements were inserted." );
181175
equals( a[1].id, "tName2ID", "Make sure the right number of elements were inserted." );
182176

183-
equals( jQuery("[name=tName1]")[0], a[0], "Find elements that have similar IDs" );
184-
equals( jQuery("[name=tName2]")[0], a[1], "Find elements that have similar IDs" );
177+
t( "Find elements that have similar IDs", "[name=tName1]", ["tName1ID"] );
178+
t( "Find elements that have similar IDs", "[name=tName2]", ["tName2ID"] );
185179
t( "Find elements that have similar IDs", "#tName2ID", ["tName2ID"] );
186180

187181
a.remove();
@@ -197,7 +191,7 @@ test("multiple", function() {
197191
});
198192

199193
test("child and adjacent", function() {
200-
expect(27);
194+
expect(29);
201195
t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
202196
t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
203197
t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
@@ -209,6 +203,7 @@ test("child and adjacent", function() {
209203
t( "Adjacent", "a +a", ["groups"] );
210204
t( "Adjacent", "a+ a", ["groups"] );
211205
t( "Adjacent", "a+a", ["groups"] );
206+
t( "Adjacent", "a:eq(1)+a", ["groups"] );
212207
t( "Adjacent", "p + p", ["ap","en","sap"] );
213208
t( "Adjacent", "p#firstp + p", ["ap"] );
214209
t( "Adjacent", "p[lang=en] + p", ["sap"] );
@@ -219,6 +214,7 @@ test("child and adjacent", function() {
219214
t( "Element Preceded By", "#groups ~ a", ["mark"] );
220215
t( "Element Preceded By", "#length ~ input", ["idTest"] );
221216
t( "Element Preceded By", "#siblingfirst ~ em", ["siblingnext"] );
217+
t( "Element Preceded By", "#siblingfirst:first ~ em", ["siblingnext"] );
222218

223219
t( "Verify deep class selector", "div.blah > p > a", [] );
224220

@@ -232,7 +228,7 @@ test("child and adjacent", function() {
232228
});
233229

234230
test("attributes", function() {
235-
expect(35);
231+
expect(34);
236232
t( "Attribute Exists", "a[title]", ["google"] );
237233
t( "Attribute Exists", "*[title]", ["google"] );
238234
t( "Attribute Exists", "[title]", ["google"] );
@@ -270,9 +266,6 @@ test("attributes", function() {
270266
t( "Attribute Contains", "a[href *= 'google']", ["google","groups"] );
271267
t( "Attribute Is Not Equal", "#ap a[hreflang!='en']", ["google","groups","anchor1"] );
272268

273-
var opt = document.getElementById("option1a");
274-
ok( (window.Sizzle || window.jQuery.find).matchesSelector( opt, "[id*=option1][type!=checkbox]" ), "Attribute Is Not Equal Matches" );
275-
276269
t("Empty values", "#select1 option[value='']", ["option1a"]);
277270
t("Empty values", "#select1 option[value!='']", ["option1b","option1c","option1d"]);
278271

@@ -287,7 +280,7 @@ test("pseudo - child", function() {
287280
expect(31);
288281
t( "First Child", "p:first-child", ["firstp","sndp"] );
289282
t( "Last Child", "p:last-child", ["sap"] );
290-
t( "Only Child", "#main a:only-child", ["simon1","anchor1","yahoo","anchor2","liveLink1","liveLink2"] );
283+
t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2","liveLink1","liveLink2"] );
291284
t( "Empty", "ul:empty", ["firstUL"] );
292285
t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
293286

@@ -301,10 +294,10 @@ test("pseudo - child", function() {
301294

302295
t( "First Child", "p:first-child", [] );
303296

304-
QUnit.reset();
297+
reset();
305298

306299
t( "Last Child", "p:last-child", ["sap"] );
307-
t( "Last Child", "#main a:last-child", ["simon1","anchor1","mark","yahoo","anchor2","simon","liveLink1","liveLink2"] );
300+
t( "Last Child", "a:last-child", ["simon1","anchor1","mark","yahoo","anchor2","simon","liveLink1","liveLink2"] );
308301

309302
t( "Nth-child", "#main form#form > *:nth-child(2)", ["text1"] );
310303
t( "Nth-child", "#main form#form > :nth-child(2)", ["text1"] );
@@ -330,27 +323,23 @@ test("pseudo - child", function() {
330323
});
331324

332325
test("pseudo - misc", function() {
333-
expect(7);
326+
expect(6);
334327

335328
t( "Headers", ":header", ["qunit-header", "qunit-banner", "qunit-userAgent"] );
336329
t( "Has Children - :has()", "p:has(a)", ["firstp","ap","en","sap"] );
337-
338-
var select = document.getElementById("select1");
339-
ok( (window.Sizzle || window.jQuery.find).matchesSelector( select, ":has(option)" ), "Has Option Matches" );
340330

341-
t( "Text Contains", "a:contains(Google)", ["google","groups"] );
342-
t( "Text Contains", "a:contains(Google Groups)", ["groups"] );
331+
t( "Text Contains", "a:contains('Google')", ["google","groups"] );
332+
t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
343333

344-
t( "Text Contains", "a:contains(Google Groups (Link))", ["groups"] );
345-
t( "Text Contains", "a:contains((Link))", ["groups"] );
334+
t( "Text Contains", "a:contains('Google Groups (Link)')", ["groups"] );
335+
t( "Text Contains", "a:contains('(Link)')", ["groups"] );
346336
});
347337

348338

349339
test("pseudo - :not", function() {
350340
expect(24);
351341
t( "Not", "a.blog:not(.link)", ["mark"] );
352-
353-
t( "Not - multiple", "#form option:not(:contains(Nothing),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d", "option3e", "option4e", "option5b", "option5c"] );
342+
t( "Not - multiple", "#form option:not(:contains('Nothing'),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d", "option3e"] );
354343
t( "Not - recursive", "#form option:not(:not(:selected))[id^='option3']", [ "option3b", "option3c"] );
355344

356345
t( ":not() failing interior", "p:not(.foo)", ["firstp","ap","sndp","en","sap","first"] );
@@ -371,9 +360,9 @@ test("pseudo - :not", function() {
371360

372361
t( "No element not selector", ".container div:not(.excluded) div", [] );
373362

374-
t( ":not() Existing attribute", "#form select:not([multiple])", ["select1", "select2", "select5"]);
375-
t( ":not() Equals attribute", "#form select:not([name=select1])", ["select2", "select3", "select4","select5"]);
376-
t( ":not() Equals quoted attribute", "#form select:not([name='select1'])", ["select2", "select3", "select4", "select5"]);
363+
t( ":not() Existing attribute", "#form select:not([multiple])", ["select1", "select2"]);
364+
t( ":not() Equals attribute", "#form select:not([name=select1])", ["select2", "select3"]);
365+
t( ":not() Equals quoted attribute", "#form select:not([name='select1'])", ["select2", "select3"]);
377366

378367
t( ":not() Multiple Class", "#foo a:not(.blog)", ["yahoo","anchor2"] );
379368
t( ":not() Multiple Class", "#foo a:not(.link)", ["yahoo","anchor2"] );
@@ -439,13 +428,13 @@ test("pseudo - visibility", function() {
439428
test("pseudo - form", function() {
440429
expect(8);
441430

442-
t( "Form element :input", "#form :input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "search", "button", "area1", "select1", "select2", "select3", "select4", "select5"] );
431+
t( "Form element :input", "#form :input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "search", "button", "area1", "select1", "select2", "select3"] );
443432
t( "Form element :radio", "#form :radio", ["radio1", "radio2"] );
444433
t( "Form element :checkbox", "#form :checkbox", ["check1", "check2"] );
445434
t( "Form element :text", "#form :text:not(#search)", ["text1", "text2", "hidden2", "name"] );
446435
t( "Form element :radio:checked", "#form :radio:checked", ["radio2"] );
447436
t( "Form element :checkbox:checked", "#form :checkbox:checked", ["check1"] );
448437
t( "Form element :radio:checked, :checkbox:checked", "#form :radio:checked, #form :checkbox:checked", ["radio2", "check1"] );
449438

450-
t( "Selected Option Element", "#form option:selected", ["option1a","option2d","option3b","option3c","option4b","option4c","option4d","option5a"] );
439+
t( "Selected Option Element", "#form option:selected", ["option1a","option2d","option3b","option3c"] );
451440
});

0 commit comments

Comments
 (0)