mirror of
https://github.com/actions/cache.git
synced 2025-12-16 19:18:36 +08: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);
|
||||
});
|
||||
|
||||
test("getCompressionLevel returns undefined for negative values", () => {
|
||||
test("getCompressionLevel returns undefined and warns for negative values", () => {
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
|
||||
testUtils.setInput("foo", "-3");
|
||||
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", () => {
|
||||
|
|
|
|||
11
dist/restore/index.js
vendored
11
dist/restore/index.js
vendored
|
|
@ -44358,12 +44358,15 @@ function getInputAsInt(name, options) {
|
|||
return value;
|
||||
}
|
||||
function getCompressionLevel(name, options) {
|
||||
const compressionLevel = getInputAsInt(name, options);
|
||||
if (compressionLevel === undefined) {
|
||||
const rawValue = core.getInput(name, options);
|
||||
if (rawValue === "") {
|
||||
return undefined;
|
||||
}
|
||||
if (compressionLevel > 9) {
|
||||
logWarning(`Invalid compression-level provided: ${compressionLevel}. Expected a value between 0 (no compression) and 9 (maximum compression).`);
|
||||
const compressionLevel = parseInt(rawValue, 10);
|
||||
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 compressionLevel;
|
||||
|
|
|
|||
|
|
@ -62,15 +62,21 @@ export function getCompressionLevel(
|
|||
name: string,
|
||||
options?: core.InputOptions
|
||||
): number | undefined {
|
||||
const compressionLevel = getInputAsInt(name, options);
|
||||
const rawValue = core.getInput(name, options);
|
||||
|
||||
if (compressionLevel === undefined) {
|
||||
if (rawValue === "") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (compressionLevel > 9) {
|
||||
const compressionLevel = parseInt(rawValue, 10);
|
||||
|
||||
if (
|
||||
isNaN(compressionLevel) ||
|
||||
compressionLevel < 0 ||
|
||||
compressionLevel > 9
|
||||
) {
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user