Skip to content

Commit

Permalink
readline: cursorTo throw error on NaN
Browse files Browse the repository at this point in the history
Fixes: #36301

PR-URL: #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>
  • Loading branch information
Lxxyx authored and aduh95 committed Dec 15, 2020
1 parent 0a5969c commit 45dbcbe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-readline-csi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);

0 comments on commit 45dbcbe

Please sign in to comment.