mirror of
https://github.com/actions/cache.git
synced 2025-12-18 15:39:54 +00:00
validate compression level input better
This commit is contained in:
parent
114dd526d5
commit
e4df80e331
@ -197,12 +197,14 @@ test("getCompressionLevel allows zero for no compression", () => {
|
|||||||
expect(actionUtils.getCompressionLevel("foo")).toBe(0);
|
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");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
|
|
||||||
testUtils.setInput("foo", "-3");
|
testUtils.setInput("foo", "-3");
|
||||||
expect(actionUtils.getCompressionLevel("foo")).toBeUndefined();
|
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", () => {
|
test("getCompressionLevel returns undefined and warns if input is too large", () => {
|
||||||
|
|||||||
11
dist/restore/index.js
vendored
11
dist/restore/index.js
vendored
@ -44358,12 +44358,15 @@ function getInputAsInt(name, options) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
function getCompressionLevel(name, options) {
|
function getCompressionLevel(name, options) {
|
||||||
const compressionLevel = getInputAsInt(name, options);
|
const rawValue = core.getInput(name, options);
|
||||||
if (compressionLevel === undefined) {
|
if (rawValue === "") {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if (compressionLevel > 9) {
|
const compressionLevel = parseInt(rawValue, 10);
|
||||||
logWarning(`Invalid compression-level provided: ${compressionLevel}. Expected a value between 0 (no compression) and 9 (maximum compression).`);
|
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 undefined;
|
||||||
}
|
}
|
||||||
return compressionLevel;
|
return compressionLevel;
|
||||||
|
|||||||
@ -62,15 +62,21 @@ export function getCompressionLevel(
|
|||||||
name: string,
|
name: string,
|
||||||
options?: core.InputOptions
|
options?: core.InputOptions
|
||||||
): number | undefined {
|
): number | undefined {
|
||||||
const compressionLevel = getInputAsInt(name, options);
|
const rawValue = core.getInput(name, options);
|
||||||
|
|
||||||
if (compressionLevel === undefined) {
|
if (rawValue === "") {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compressionLevel > 9) {
|
const compressionLevel = parseInt(rawValue, 10);
|
||||||
|
|
||||||
|
if (
|
||||||
|
isNaN(compressionLevel) ||
|
||||||
|
compressionLevel < 0 ||
|
||||||
|
compressionLevel > 9
|
||||||
|
) {
|
||||||
logWarning(
|
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;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user