mirror of
https://github.com/actions/cache.git
synced 2024-11-13 17:38:05 +00:00
Use parseInt instead of Number to handle empty strings
This commit is contained in:
parent
a6f1f4b32e
commit
4bceb75b5b
@ -15,7 +15,6 @@ beforeAll(() => {
|
|||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
delete process.env[Events.Key];
|
delete process.env[Events.Key];
|
||||||
delete process.env[RefKey];
|
delete process.env[RefKey];
|
||||||
testUtils.clearInputs();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isGhes returns true if server url is not github.com", () => {
|
test("isGhes returns true if server url is not github.com", () => {
|
||||||
@ -215,7 +214,7 @@ test("getInputAsArray handles empty lines correctly", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("getInputAsInt returns undefined if input not set", () => {
|
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", () => {
|
test("getInputAsInt returns value if input is valid", () => {
|
||||||
@ -227,3 +226,9 @@ test("getInputAsInt returns undefined if input is invalid or NaN", () => {
|
|||||||
testUtils.setInput("foo", "bar");
|
testUtils.setInput("foo", "bar");
|
||||||
expect(actionUtils.getInputAsInt("foo")).toBeUndefined();
|
expect(actionUtils.getInputAsInt("foo")).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("getInputAsInt throws if required and value missing", () => {
|
||||||
|
expect(() =>
|
||||||
|
actionUtils.getInputAsInt("undefined", { required: true })
|
||||||
|
).toThrowError();
|
||||||
|
});
|
||||||
|
4
dist/restore/index.js
vendored
4
dist/restore/index.js
vendored
@ -31354,8 +31354,8 @@ function getInputAsArray(name, options) {
|
|||||||
}
|
}
|
||||||
exports.getInputAsArray = getInputAsArray;
|
exports.getInputAsArray = getInputAsArray;
|
||||||
function getInputAsInt(name, options) {
|
function getInputAsInt(name, options) {
|
||||||
const value = Number(core.getInput(name, options));
|
const value = parseInt(core.getInput(name, options));
|
||||||
if (Number.isNaN(value) || value < 0) {
|
if (isNaN(value) || value < 0) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
4
dist/save/index.js
vendored
4
dist/save/index.js
vendored
@ -31354,8 +31354,8 @@ function getInputAsArray(name, options) {
|
|||||||
}
|
}
|
||||||
exports.getInputAsArray = getInputAsArray;
|
exports.getInputAsArray = getInputAsArray;
|
||||||
function getInputAsInt(name, options) {
|
function getInputAsInt(name, options) {
|
||||||
const value = Number(core.getInput(name, options));
|
const value = parseInt(core.getInput(name, options));
|
||||||
if (Number.isNaN(value) || value < 0) {
|
if (isNaN(value) || value < 0) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
@ -68,8 +68,8 @@ export function getInputAsInt(
|
|||||||
name: string,
|
name: string,
|
||||||
options?: core.InputOptions
|
options?: core.InputOptions
|
||||||
): number | undefined {
|
): number | undefined {
|
||||||
const value = Number(core.getInput(name, options));
|
const value = parseInt(core.getInput(name, options));
|
||||||
if (Number.isNaN(value) || value < 0) {
|
if (isNaN(value) || value < 0) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
Loading…
Reference in New Issue
Block a user