mirror of https://github.com/nodejs/node.git
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: https://github.com/nodejs/node/pull/18611 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>pull/18591/merge
parent
1fc373bdf6
commit
656a5d042d
|
@ -184,6 +184,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];
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ const { EOL } = require('os');
|
|||
const EventEmitter = require('events');
|
||||
const { errorCache } = require('internal/errors');
|
||||
const { writeFileSync, unlinkSync } = require('fs');
|
||||
const { inspect } = require('util');
|
||||
const a = assert;
|
||||
|
||||
assert.ok(a.AssertionError.prototype instanceof Error,
|
||||
|
@ -565,6 +566,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(
|
||||
|
|
Loading…
Reference in New Issue