readline: cursorTo throw error on NaN

Fixes: https://github.com/nodejs/node/issues/36301

PR-URL: https://github.com/nodejs/node/pull/36379
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Zijian Liu
2020-12-04 13:25:15 +08:00
committed by Antoine du Hamel
parent 0a5969c62a
commit 45dbcbef90
2 changed files with 18 additions and 0 deletions

View File

@@ -1236,6 +1236,11 @@ function cursorTo(stream, x, y, callback) {
y = undefined;
}
if (NumberIsNaN(x))
throw new ERR_INVALID_ARG_VALUE('x', x);
if (NumberIsNaN(y))
throw new ERR_INVALID_ARG_VALUE('y', y);
if (stream == null || (typeof x !== 'number' && typeof y !== 'number')) {
if (typeof callback === 'function')
process.nextTick(callback, null);

View File

@@ -161,3 +161,16 @@ assert.strictEqual(writable.data, '\x1b[2G');
assert.throws(() => {
readline.cursorTo(writable, 1, 1, null);
}, /ERR_INVALID_CALLBACK/);
// Verify that cursorTo() throws if x or y is NaN.
assert.throws(() => {
readline.cursorTo(writable, NaN);
}, /ERR_INVALID_ARG_VALUE/);
assert.throws(() => {
readline.cursorTo(writable, 1, NaN);
}, /ERR_INVALID_ARG_VALUE/);
assert.throws(() => {
readline.cursorTo(writable, NaN, NaN);
}, /ERR_INVALID_ARG_VALUE/);