Skip to content

Commit

Permalink
Fixed empty args input parsing.
Browse files Browse the repository at this point in the history
Resolved issue where an empty args input would result
in an array containing a single empty string, which would
cause command execution failures.

- Added filter when getting args input to remove any empty strings.
  from the resulting array.
- Added unit test to verify this case.
  • Loading branch information
MrFlynn committed Jul 7, 2024
1 parent 81b3809 commit 7f1ce4f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
21 changes: 21 additions & 0 deletions __tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@ describe("getInputs", () => {
script: "script.js",
});
});

it("returns empty args list when none are given", () => {
(getInput as jest.Mock).mockImplementation((name, _) => {
switch (name) {
case "version":
return "";
case "args":
return "";
case "script":
return "script.js";
default:
throw `Unexpected config name ${name}`;
}
});

expect(config.getInputs()).toStrictEqual({
version: "latest",
args: [],
script: "script.js",
});
});
});

describe("getPlatform", () => {
Expand Down
5 changes: 4 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export interface Inputs {
export function getInputs(): Inputs {
return {
version: core.getInput("version") || "latest",
args: core.getInput("args").split(" "),
args: core
.getInput("args")
.split(" ")
.filter((el) => el !== ""),
script: core.getInput("script", { required: true }),
};
}
Expand Down

0 comments on commit 7f1ce4f

Please sign in to comment.