aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorBruno PIERRE <brunopierre4@yahoo.fr>2022-01-24 18:55:16 +0100
committerGitHub <noreply@github.com>2022-01-24 18:55:16 +0100
commit9c6f64c7b51d50e334ef1183e2937ad77c0a68b0 (patch)
tree769a1b64a6760c6e21831d5f4b35d3a610e37162 /test/unit
parenteb9ceb2facbeff1c66a41824bd0ac0c56d0c5c62 (diff)
downloadjquery-9c6f64c7b51d50e334ef1183e2937ad77c0a68b0.tar.gz
jquery-9c6f64c7b51d50e334ef1183e2937ad77c0a68b0.zip
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:4 Closes gh-4986
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/selector.js12
1 files changed, 7 insertions, 5 deletions
diff --git a/test/unit/selector.js b/test/unit/selector.js
index 6cf288c19..2b0c251cf 100644
--- a/test/unit/selector.js
+++ b/test/unit/selector.js
@@ -1895,9 +1895,7 @@ QUnit.test( "jQuery.uniqueSort", function( assert ) {
}
}
Arrayish.prototype = {
- slice: [].slice,
- sort: [].sort,
- splice: [].splice
+ sliceForTestOnly: [].slice
};
var i, tests,
@@ -1959,8 +1957,12 @@ QUnit.test( "jQuery.uniqueSort", function( assert ) {
jQuery.each( tests, function( label, test ) {
var length = test.length || test.input.length;
- assert.deepEqual( jQuery.uniqueSort( test.input ).slice( 0, length ), test.expected, label + " (array)" );
- assert.deepEqual( jQuery.uniqueSort( new Arrayish( test.input ) ).slice( 0, length ), test.expected, label + " (quasi-array)" );
+ // We duplicate `test.input` because otherwise it is modified by `uniqueSort`
+ // and the second test becomes worthless.
+ assert.deepEqual( jQuery.uniqueSort( test.input.slice( 0 ) ).slice( 0, length ),
+ test.expected, label + " (array)" );
+ assert.deepEqual( jQuery.uniqueSort( new Arrayish( test.input ) ).sliceForTestOnly( 0, length ),
+ test.expected, label + " (quasi-array)" );
} );
} );