Skip to content

Commit 45dbcbe

Browse files
Lxxyxaduh95
authored andcommitted
readline: cursorTo throw error on NaN
Fixes: #36301 PR-URL: #36379 Reviewed-By: Zeyu Yang <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 0a5969c commit 45dbcbe

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Diff for: lib/readline.js

+5
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,11 @@ function cursorTo(stream, x, y, callback) {
12361236
y = undefined;
12371237
}
12381238

1239+
if (NumberIsNaN(x))
1240+
throw new ERR_INVALID_ARG_VALUE('x', x);
1241+
if (NumberIsNaN(y))
1242+
throw new ERR_INVALID_ARG_VALUE('y', y);
1243+
12391244
if (stream == null || (typeof x !== 'number' && typeof y !== 'number')) {
12401245
if (typeof callback === 'function')
12411246
process.nextTick(callback, null);

Diff for: test/parallel/test-readline-csi.js

+13
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,16 @@ assert.strictEqual(writable.data, '\x1b[2G');
161161
assert.throws(() => {
162162
readline.cursorTo(writable, 1, 1, null);
163163
}, /ERR_INVALID_CALLBACK/);
164+
165+
// Verify that cursorTo() throws if x or y is NaN.
166+
assert.throws(() => {
167+
readline.cursorTo(writable, NaN);
168+
}, /ERR_INVALID_ARG_VALUE/);
169+
170+
assert.throws(() => {
171+
readline.cursorTo(writable, 1, NaN);
172+
}, /ERR_INVALID_ARG_VALUE/);
173+
174+
assert.throws(() => {
175+
readline.cursorTo(writable, NaN, NaN);
176+
}, /ERR_INVALID_ARG_VALUE/);

0 commit comments

Comments
 (0)