mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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:
committed by
Antoine du Hamel
parent
0a5969c62a
commit
45dbcbef90
@@ -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);
|
||||
|
||||
@@ -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/);
|
||||
|
||||
Reference in New Issue
Block a user