Skip to content

Commit

Permalink
Use parseInt instead of Number to handle empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Hadka committed Oct 2, 2020
1 parent a6f1f4b commit 4bceb75
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
9 changes: 7 additions & 2 deletions __tests__/actionUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ beforeAll(() => {
afterEach(() => {
delete process.env[Events.Key];
delete process.env[RefKey];
testUtils.clearInputs();
});

test("isGhes returns true if server url is not github.com", () => {
Expand Down Expand Up @@ -215,7 +214,7 @@ test("getInputAsArray handles empty lines correctly", () => {
});

test("getInputAsInt returns undefined if input not set", () => {
expect(actionUtils.getInputAsInt("foo")).toBeUndefined();
expect(actionUtils.getInputAsInt("undefined")).toBeUndefined();
});

test("getInputAsInt returns value if input is valid", () => {
Expand All @@ -227,3 +226,9 @@ test("getInputAsInt returns undefined if input is invalid or NaN", () => {
testUtils.setInput("foo", "bar");
expect(actionUtils.getInputAsInt("foo")).toBeUndefined();
});

test("getInputAsInt throws if required and value missing", () => {
expect(() =>
actionUtils.getInputAsInt("undefined", { required: true })
).toThrowError();
});
4 changes: 2 additions & 2 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31354,8 +31354,8 @@ function getInputAsArray(name, options) {
}
exports.getInputAsArray = getInputAsArray;
function getInputAsInt(name, options) {
const value = Number(core.getInput(name, options));
if (Number.isNaN(value) || value < 0) {
const value = parseInt(core.getInput(name, options));
if (isNaN(value) || value < 0) {
return undefined;
}
return value;
Expand Down
4 changes: 2 additions & 2 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31354,8 +31354,8 @@ function getInputAsArray(name, options) {
}
exports.getInputAsArray = getInputAsArray;
function getInputAsInt(name, options) {
const value = Number(core.getInput(name, options));
if (Number.isNaN(value) || value < 0) {
const value = parseInt(core.getInput(name, options));
if (isNaN(value) || value < 0) {
return undefined;
}
return value;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/actionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export function getInputAsInt(
name: string,
options?: core.InputOptions
): number | undefined {
const value = Number(core.getInput(name, options));
if (Number.isNaN(value) || value < 0) {
const value = parseInt(core.getInput(name, options));
if (isNaN(value) || value < 0) {
return undefined;
}
return value;
Expand Down

0 comments on commit 4bceb75

Please sign in to comment.