Encode cache keys

* remove restriction on commas in keys
* avoid 404 during save when characters like slashes are used in keys

fixes #53
This commit is contained in:
alexlamsl 2019-11-05 20:22:33 +08:00
parent f66a56e59e
commit cda609ee82

View file

@ -17,12 +17,16 @@ async function run() {
); );
core.debug(`Cache Path: ${cachePath}`); core.debug(`Cache Path: ${cachePath}`);
const primaryKey = core.getInput(Inputs.Key, { required: true }); const keys = [
core.getInput(Inputs.Key, { required: true }),
...core
.getInput(Inputs.RestoreKeys)
.split(/\s*\n\s*/)
.filter(x => x)
].map(key => encodeURIComponent(key).replace(/%/g, " "));
const primaryKey = keys[0];
core.saveState(State.CacheKey, primaryKey); core.saveState(State.CacheKey, primaryKey);
const restoreKeys = core.getInput(Inputs.RestoreKeys).split("\n");
const keys = [primaryKey, ...restoreKeys];
core.debug("Resolved Keys:"); core.debug("Resolved Keys:");
core.debug(JSON.stringify(keys)); core.debug(JSON.stringify(keys));
@ -39,13 +43,6 @@ async function run() {
); );
return; return;
} }
const regex = /^[^,]*$/;
if (!regex.test(key)) {
core.setFailed(
`Key Validation Error: ${key} cannot contain commas.`
);
return;
}
} }
try { try {