Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit05184cc

Browse files
authored
Selector: Make empty attribute selectors work in IE again
qSA in IE 11/Edge often (but not always) don't find elements with an emptyname attribute selector (`[name=""]`). Detect that & fall back to Sizzletraversal.Interestingly, IE 10 & older don't seem to have the issue.Fixesgh-4435Closesgh-4510
1 parentd0ce00c commit05184cc

File tree

7 files changed

+39
-9
lines changed

7 files changed

+39
-9
lines changed

‎src/selector.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import documentElement from "./var/documentElement.js";
55
importindexOffrom"./var/indexOf.js";
66
importpopfrom"./var/pop.js";
77
importpushfrom"./var/push.js";
8+
importwhitespacefrom"./selector/var/whitespace.js";
89
importrbuggyQSAfrom"./selector/rbuggyQSA.js";
910
importsupportfrom"./selector/support.js";
1011

@@ -41,9 +42,6 @@ var i,
4142

4243
// Regular expressions
4344

44-
// https://www.w3.org/TR/css3-selectors/#whitespace
45-
whitespace="[\\x20\\t\\r\\n\\f]",
46-
4745
// https://www.w3.org/TR/css-syntax-3/#ident-token-diagram
4846
identifier="(?:\\\\[\\da-fA-F]{1,6}"+whitespace+
4947
"?|\\\\[^\\r\\n\\f]|[\\w-]|[^\0-\\x7f])+",

‎src/selector/rbuggyQSA.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
importdocumentfrom"../var/document.js";
22
importisIEfrom"../var/isIE.js";
3+
importwhitespacefrom"./var/whitespace.js";
34

45
varrbuggyQSA=[],
5-
testEl=document.createElement("div");
6+
testEl=document.createElement("div"),
7+
input=document.createElement("input");
68

79
testEl.innerHTML="<a href=''></a>";
810

@@ -19,6 +21,18 @@ if ( isIE ) {
1921
rbuggyQSA.push(":enabled",":disabled");
2022
}
2123

24+
// Support: IE 11+, Edge 15 - 18+
25+
// IE 11/Edge don't find elements on a `[name='']` query in some cases.
26+
// Adding a temporary attribute to the document before the selection works
27+
// around the issue.
28+
// Interestingly, IE 10 & older don't seem to have the issue.
29+
input.setAttribute("name","");
30+
testEl.appendChild(input);
31+
if(!testEl.querySelectorAll("[name='']").length){
32+
rbuggyQSA.push("\\["+whitespace+"*name"+whitespace+"*="+
33+
whitespace+"*(?:''|\"\")");
34+
}
35+
2236
rbuggyQSA=rbuggyQSA.length&&newRegExp(rbuggyQSA.join("|"));
2337

2438
exportdefaultrbuggyQSA;

‎src/selector/var/whitespace.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// https://www.w3.org/TR/css3-selectors/#whitespace
2+
exportdefault"[\\x20\\t\\r\\n\\f]";

‎test/data/qunit-fixture.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@
116116
<inputtype="radio"name="R1"value="2"/>
117117
<inputtype="text"name="My Name"value="me"/>
118118
<inputtype="reset"name="reset"value="NO"/>
119+
<divclass="empty-name-container">
120+
<divid="empty-name-parent">
121+
<inputtype="text"id="name-empty"name=""value=""/>
122+
</div>
123+
</div>
119124
<selectname="S1">
120125
<optionvalue="abc">ABC</option>
121126
<optionvalue="abc">ABC</option>

‎test/data/qunit-fixture.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎test/unit/attributes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ QUnit.test( "addClass(Array)", function( assert ) {
12551255
});
12561256

12571257
QUnit.test("addClass(Function) with incoming value",function(assert){
1258-
assert.expect(57);
1258+
assert.expect(59);
12591259
varpass,i,
12601260
div=jQuery("#qunit-fixture div"),
12611261
old=div.map(function(){
@@ -1330,7 +1330,7 @@ QUnit.test( "removeClass(Array) - simple", function( assert ) {
13301330
});
13311331

13321332
QUnit.test("removeClass(Function) with incoming value",function(assert){
1333-
assert.expect(57);
1333+
assert.expect(59);
13341334

13351335
var$divs=jQuery("#qunit-fixture div").addClass("test"),old=$divs.map(function(){
13361336
returnjQuery(this).attr("class");

‎test/unit/selector.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ QUnit.test( "attributes - special characters", function( assert ) {
720720
});
721721

722722
QUnit.test("attributes - others",function(assert){
723-
assert.expect(10);
723+
assert.expect(14);
724724

725725
vardiv=document.getElementById("foo");
726726

@@ -750,6 +750,17 @@ QUnit.test( "attributes - others", function( assert ) {
750750
assert.ok(!jQuery("<input type='checkbox'/>").prop("checked",true).is("[checked]"),
751751
"[checked] selects by attribute (negative)"
752752
);
753+
754+
assert.t("empty name","[name='']",["name-empty"]);
755+
assert.t("prefixed empty name","#empty-name-parent [name='']",["name-empty"]);
756+
757+
varemptyNameContainer=jQuery(".empty-name-container");
758+
assert.deepEqual(emptyNameContainer.find("[name='']").get(),
759+
q("name-empty"),
760+
"empty name with context");
761+
assert.deepEqual(emptyNameContainer.find("#empty-name-parent [name='']").get(),
762+
q("name-empty"),
763+
"prefixed empty name with context");
753764
});
754765

755766
QUnit.test("pseudo - (parent|empty)",function(assert){
@@ -1257,7 +1268,7 @@ QUnit[ QUnit.jQuerySelectorsPos ? "test" : "skip" ]( "pseudo - position", functi
12571268

12581269
assert.t("Check element position","#qunit-fixture div div:eq(0)",["nothiddendivchild"]);
12591270
assert.t("Check element position","#select1 option:eq(3)",["option1d"]);
1260-
assert.t("Check element position","#qunit-fixture div div:eq(10)",["names-group"]);
1271+
assert.t("Check element position","#qunit-fixture div div:eq(10)",["no-clone-exception"]);
12611272
assert.t("Check element position","#qunit-fixture div div:first",["nothiddendivchild"]);
12621273
assert.t("Check element position","#qunit-fixture div > div:first",["nothiddendivchild"]);
12631274
assert.t("Check element position","#qunit-fixture div:first a:first",["yahoo"]);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp