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

Commit9c6f64c

Browse files
authored
Core: Don't rely on splice being present on input
Without this fix calling `jQuery.uniqueSort` on an array-like can result in:TypeError: results.splice is not a function at Function.jQuery.uniqueSort (https://code.jquery.com/jquery-git.js:664:12) at jQuery.fn.init.find (https://code.jquery.com/jquery-git.js:2394:27) at gocusihafe.js:3:4Closesgh-4986
1 parenteb9ceb2 commit9c6f64c

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

‎src/selector/uniqueSort.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
importjQueryfrom"../core.js";
22
importdocumentfrom"../var/document.js";
33
importsortfrom"../var/sort.js";
4+
importsplicefrom"../var/splice.js";
45

56
varhasDuplicate;
67

@@ -80,7 +81,7 @@ jQuery.uniqueSort = function( results ) {
8081
}
8182
}
8283
while(j--){
83-
results.splice(duplicates[j],1);
84+
splice.call(results,duplicates[j],1);
8485
}
8586
}
8687

‎src/var/splice.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
importarrfrom"./arr.js";
2+
3+
exportdefaultarr.splice;

‎test/unit/selector.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,9 +1895,7 @@ QUnit.test( "jQuery.uniqueSort", function( assert ) {
18951895
}
18961896
}
18971897
Arrayish.prototype={
1898-
slice:[].slice,
1899-
sort:[].sort,
1900-
splice:[].splice
1898+
sliceForTestOnly:[].slice
19011899
};
19021900

19031901
vari,tests,
@@ -1959,8 +1957,12 @@ QUnit.test( "jQuery.uniqueSort", function( assert ) {
19591957

19601958
jQuery.each(tests,function(label,test){
19611959
varlength=test.length||test.input.length;
1962-
assert.deepEqual(jQuery.uniqueSort(test.input).slice(0,length),test.expected,label+" (array)");
1963-
assert.deepEqual(jQuery.uniqueSort(newArrayish(test.input)).slice(0,length),test.expected,label+" (quasi-array)");
1960+
// We duplicate `test.input` because otherwise it is modified by `uniqueSort`
1961+
// and the second test becomes worthless.
1962+
assert.deepEqual(jQuery.uniqueSort(test.input.slice(0)).slice(0,length),
1963+
test.expected,label+" (array)");
1964+
assert.deepEqual(jQuery.uniqueSort(newArrayish(test.input)).sliceForTestOnly(0,length),
1965+
test.expected,label+" (quasi-array)");
19641966
});
19651967
});
19661968

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp