Skip to content

Commit 21dde30

Browse files
committed
Provide a graceful failover for [name=foo] queries that are looking for non-input/iframe/form elements. Fixes jQuery bug jquery#4081.
1 parent 782b4af commit 21dde30

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/selector.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,9 @@ var Expr = Sizzle.selectors = {
333333
}
334334
},
335335
NAME: function(match, context, isXML){
336-
if ( typeof context.getElementsByName !== "undefined" && !isXML ) {
337-
return context.getElementsByName(match[1]);
336+
if ( typeof context.getElementsByName !== "undefined" ) {
337+
var ret = context.getElementsByName(match[1]);
338+
return ret.length === 0 ? null : ret;
338339
}
339340
},
340341
TAG: function(match, context){

test/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ <h2 id="userAgent"></h2>
121121
<input name="types[]" id="types_movie" type="checkbox" value="movie" />
122122
</form>
123123

124-
<div id="fx-queue">
125-
<div id="fadein" class='chain test'>fadeIn<div>fadeIn</div></div>
124+
<div id="fx-queue" name="test">
125+
<div id="fadein" class='chain test' name='div'>fadeIn<div>fadeIn</div></div>
126126
<div id="fadeout" class='chain test out'>fadeOut<div>fadeOut</div></div>
127127

128128
<div id="show" class='chain test'>show<div>show</div></div>

test/unit/selector.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,14 @@ test("class", function() {
134134
});
135135

136136
test("name", function() {
137-
expect(7);
137+
expect(9);
138138

139139
t( "Name selector", "input[name=action]", ["text1"] );
140140
t( "Name selector with single quotes", "input[name='action']", ["text1"] );
141141
t( "Name selector with double quotes", 'input[name="action"]', ["text1"] );
142142

143+
t( "Name selector non-input", "[name=test]", ["length", "fx-queue"] );
144+
t( "Name selector non-input", "[name=div]", ["fadein"] );
143145
t( "Name selector non-input", "*[name=iframe]", ["iframe"] );
144146

145147
t( "Name selector for grouped input", "input[name='types[]']", ["types_all", "types_anime", "types_movie"] )

0 commit comments

Comments
 (0)