From 6514a4128c3e7aa6c1bb1c6f3f018412fa76e5d9 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 21 Nov 2013 13:23:43 +0100 Subject: [PATCH] test: fix array sorting bug `a === a.sort()` is always true because Array#sort() does an in-place sort. Make a copy of the array first. --- test/simple/test-crypto.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/simple/test-crypto.js b/test/simple/test-crypto.js index 7afb958a91..d862fc3445 100644 --- a/test/simple/test-crypto.js +++ b/test/simple/test-crypto.js @@ -24,6 +24,7 @@ var common = require('../common'); var assert = require('assert'); +var util = require('util'); try { var crypto = require('crypto'); @@ -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.