Skip to content

Commit

Permalink
test: fix array sorting bug
Browse files Browse the repository at this point in the history
`a === a.sort()` is always true because Array#sort() does an in-place
sort.  Make a copy of the array first.
  • Loading branch information
bnoordhuis authored and indutny committed Jan 22, 2014
1 parent 74d9aa4 commit 6514a41
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/simple/test-crypto.js
Expand Up @@ -24,6 +24,7 @@

var common = require('../common');
var assert = require('assert');
var util = require('util');

try {
var crypto = require('crypto');
Expand Down Expand Up @@ -926,7 +927,9 @@ testPBKDF2('pass\0word', 'sa\0lt', 4096, 16,
})();

function assertSorted(list) {
assert.deepEqual(list, list.sort());
// Array#sort() modifies the list in place so make a copy.
var sorted = util._extend([], list).sort();
assert.deepEqual(list, sorted);
}

// Assume that we have at least AES-128-CBC.
Expand Down

0 comments on commit 6514a41

Please sign in to comment.