From e4df80e3311027354da79a736c2f72599da5d57d Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Sat, 13 Dec 2025 16:39:21 -0500 Subject: [PATCH] validate compression level input better --- __tests__/actionUtils.test.ts | 6 ++++-- dist/restore/index.js | 11 +++++++---- src/utils/actionUtils.ts | 14 ++++++++++---- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/__tests__/actionUtils.test.ts b/__tests__/actionUtils.test.ts index f8612c4..6ac8f1e 100644 --- a/__tests__/actionUtils.test.ts +++ b/__tests__/actionUtils.test.ts @@ -197,12 +197,14 @@ test("getCompressionLevel allows zero for no compression", () => { expect(actionUtils.getCompressionLevel("foo")).toBe(0); }); -test("getCompressionLevel returns undefined for negative values", () => { +test("getCompressionLevel returns undefined and warns for negative values", () => { const infoMock = jest.spyOn(core, "info"); testUtils.setInput("foo", "-3"); expect(actionUtils.getCompressionLevel("foo")).toBeUndefined(); - expect(infoMock).not.toHaveBeenCalledWith(expect.stringContaining("compression-level")); + expect(infoMock).toHaveBeenCalledWith( + "[warning]Invalid compression-level provided: -3. Expected a value between 0 (no compression) and 9 (maximum compression)." + ); }); test("getCompressionLevel returns undefined and warns if input is too large", () => { diff --git a/dist/restore/index.js b/dist/restore/index.js index 4d2597a..be87c72 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -44358,12 +44358,15 @@ function getInputAsInt(name, options) { return value; } function getCompressionLevel(name, options) { - const compressionLevel = getInputAsInt(name, options); - if (compressionLevel === undefined) { + const rawValue = core.getInput(name, options); + if (rawValue === "") { return undefined; } - if (compressionLevel > 9) { - logWarning(`Invalid compression-level provided: ${compressionLevel}. Expected a value between 0 (no compression) and 9 (maximum compression).`); + const compressionLevel = parseInt(rawValue, 10); + if (isNaN(compressionLevel) || + compressionLevel < 0 || + compressionLevel > 9) { + logWarning(`Invalid compression-level provided: ${rawValue}. Expected a value between 0 (no compression) and 9 (maximum compression).`); return undefined; } return compressionLevel; diff --git a/src/utils/actionUtils.ts b/src/utils/actionUtils.ts index 6d1de9c..0b6c008 100644 --- a/src/utils/actionUtils.ts +++ b/src/utils/actionUtils.ts @@ -62,15 +62,21 @@ export function getCompressionLevel( name: string, options?: core.InputOptions ): number | undefined { - const compressionLevel = getInputAsInt(name, options); + const rawValue = core.getInput(name, options); - if (compressionLevel === undefined) { + if (rawValue === "") { return undefined; } - if (compressionLevel > 9) { + const compressionLevel = parseInt(rawValue, 10); + + if ( + isNaN(compressionLevel) || + compressionLevel < 0 || + compressionLevel > 9 + ) { logWarning( - `Invalid compression-level provided: ${compressionLevel}. Expected a value between 0 (no compression) and 9 (maximum compression).` + `Invalid compression-level provided: ${rawValue}. Expected a value between 0 (no compression) and 9 (maximum compression).` ); return undefined; }