From 058cbecaeb134ed25c1ebf14aae40f1041ec8814 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Tue, 10 Nov 2026 12:54:54 +1300 Subject: [PATCH] fix: only treat an all-digit `workflow` input as a workflow ID `parseInt` accepted a numeric prefix, so a filename such as `01-build.yml` was dispatched as workflow ID 1. --- src/action.spec.ts | 10 ++++++++++ src/action.ts | 29 +++-------------------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/action.spec.ts b/src/action.spec.ts index 9acf9480..279e52f4 100644 --- a/src/action.spec.ts +++ b/src/action.spec.ts @@ -69,6 +69,16 @@ describe("Action", () => { expect(config.workflow).toStrictEqual(123456); }); + it.each(["01-build.yml", "2024-release.yml", "0x1F", "12e3"])( + "should keep a workflow filename starting with digits as a string: %s", + (workflow) => { + mockEnvConfig.workflow = workflow; + const config: ActionConfig = getConfig(); + + expect(config.workflow).toStrictEqual(workflow); + }, + ); + it("should handle no inputs being provided", () => { mockEnvConfig.workflow_inputs = ""; const config: ActionConfig = getConfig(); diff --git a/src/action.ts b/src/action.ts index 973c9fde..ffd0a193 100644 --- a/src/action.ts +++ b/src/action.ts @@ -55,24 +55,6 @@ export function getConfig(): ActionConfig { }; } -function getNumberFromValue(value: string): number | undefined { - if (value === "") { - return undefined; - } - - try { - const num = parseInt(value); - - if (isNaN(num)) { - throw new Error("Parsed value is NaN"); - } - - return num; - } catch { - throw new Error(`Unable to parse value: ${value}`); - } -} - function getWorkflowInputs( workflowInputs: string, ): ActionWorkflowInputs | undefined { @@ -104,12 +86,7 @@ function getWorkflowInputs( } function tryGetWorkflowAsNumber(workflowInput: string): string | number { - try { - // We can assume that the string is defined and not empty at this point. - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return getNumberFromValue(workflowInput)!; - } catch { - // Assume using a workflow name instead of an ID. - return workflowInput; - } + // Only an all-digit input is an ID. parseInt would accept a numeric prefix + // and turn a filename such as "01-build.yml" into the ID 1. + return /^\d+$/.test(workflowInput) ? Number(workflowInput) : workflowInput; }