From dad4d74f7c11eb20d8783d43caa4b29b850bd320 Mon Sep 17 00:00:00 2001 From: Aysajan Eziz Date: Thu, 16 Jul 2026 18:32:24 -0400 Subject: [PATCH] fix: reject invalid project numbers in constructor Signed-off-by: Aysajan Eziz --- index.js | 4 ++++ test/constructor.test.js | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/index.js b/index.js index c5c3d874..43994733 100644 --- a/index.js +++ b/index.js @@ -37,6 +37,10 @@ export default class GitHubProject { constructor(options) { const { owner, number, fields = {} } = options; + if (Number.isNaN(number)) { + throw new TypeError("The number option must be a valid number"); + } + // set octokit either from `options.octokit` or `options.token` const octokit = "token" in options diff --git a/test/constructor.test.js b/test/constructor.test.js index 6378b53c..f3402827 100644 --- a/test/constructor.test.js +++ b/test/constructor.test.js @@ -50,3 +50,15 @@ test("constructor with token", (t) => { t.true(project.octokit instanceof Octokit); }); + +test("rejects NaN as the number option", (t) => { + t.throws( + () => + new GitHubProject({ + owner: "owner", + number: NaN, + octokit: new Octokit(), + }), + { message: "The number option must be a valid number" }, + ); +});