Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
assert: fix infinite loop
In rare cirumstances it is possible to get a identical error diff.
In such a case the advances diffing runs into a infinite loop.
This fixes it by properly checking for extra entries.

PR-URL: #18611
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
BridgeAR committed Mar 8, 2018
commit ca8a59144eaf7dca02e7c0aee95c10320200c401
2 changes: 2 additions & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ function createErrDiff(actual, expected, operator) {
}
actualLines.pop();
expectedLines.pop();
if (actualLines.length === 0 || expectedLines.length === 0)
break;
a = actualLines[actualLines.length - 1];
b = expectedLines[expectedLines.length - 1];
}
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

const common = require('../common');
const assert = require('assert');
const { inspect } = require('util');
const a = assert;

function makeBlock(f) {
Expand Down Expand Up @@ -890,6 +891,17 @@ common.expectsError(
() => assert.deepEqual(Array(12).fill(1), Array(12).fill(2)),
{ message });

const obj1 = {};
const obj2 = { loop: 'forever' };
obj2[inspect.custom] = () => '{}';
// No infinite loop and no custom inspect.
assert.throws(() => assert.deepEqual(obj1, obj2), {
message: `${start}\n` +
`${actExp}\n` +
'\n' +
' {}'
});

// notDeepEqual tests
message = 'Identical input passed to notDeepStrictEqual:\n[\n 1\n]';
assert.throws(
Expand Down