Skip to content

Commit 9483bd5

Browse files
committed
Check that matrixObject is an object
1 parent 1ac6270 commit 9483bd5

File tree

6 files changed

+34
-11
lines changed

6 files changed

+34
-11
lines changed

lib/analyze-action-post.js

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action-post.js

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/start-proxy-action-post.js

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif-action-post.js

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/debug-artifacts.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ test("getArtifactSuffix", (t) => {
3030
t.is(debugArtifacts.getArtifactSuffix(""), "");
3131
t.is(debugArtifacts.getArtifactSuffix("invalid json"), "");
3232
t.is(debugArtifacts.getArtifactSuffix("{}"), "");
33+
t.is(debugArtifacts.getArtifactSuffix("null"), "");
34+
t.is(debugArtifacts.getArtifactSuffix("123"), "");
35+
t.is(debugArtifacts.getArtifactSuffix('"string"'), "");
3336

3437
// Suffixes for non-empty, valid `matrix` inputs.
3538
const testMatrices = [

src/debug-artifacts.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,13 @@ export function getArtifactSuffix(matrix: string | undefined): string {
260260
let suffix = "";
261261
if (matrix) {
262262
try {
263-
const matrixObject = JSON.parse(matrix) as any[][];
264-
for (const matrixKey of Object.keys(matrixObject).sort())
265-
suffix += `-${matrixObject[matrixKey]}`;
263+
const matrixObject = JSON.parse(matrix);
264+
if (matrixObject !== null && typeof matrixObject === "object") {
265+
for (const matrixKey of Object.keys(matrixObject as object).sort())
266+
suffix += `-${matrixObject[matrixKey]}`;
267+
} else {
268+
core.warning("User-specified `matrix` input is not an object.");
269+
}
266270
} catch {
267271
core.warning(
268272
"Could not parse user-specified `matrix` input into JSON. The debug artifact will not be named with the user's `matrix` input.",

0 commit comments

Comments
 (0)