Skip to content

Commit ea8a175

Browse files
Merge pull request #812 from github/sanitize-artifact-name
Sanitize artifact name before using
2 parents ea16943 + f360da7 commit ea8a175

File tree

9 files changed

+30
-6
lines changed

9 files changed

+30
-6
lines changed

lib/actions-util.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/actions-util.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/actions-util.test.js

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

lib/actions-util.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/analyze-action.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/analyze-action.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions-util.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,3 +680,13 @@ test("isAnalyzingDefaultBranch()", async (t) => {
680680
t.deepEqual(await actionsutil.isAnalyzingDefaultBranch(), false);
681681
});
682682
});
683+
684+
test("sanitizeArifactName", (t) => {
685+
t.deepEqual(actionsutil.sanitizeArifactName("hello-world_"), "hello-world_");
686+
t.deepEqual(actionsutil.sanitizeArifactName("hello`world`"), "helloworld");
687+
t.deepEqual(actionsutil.sanitizeArifactName("hello===123"), "hello123");
688+
t.deepEqual(
689+
actionsutil.sanitizeArifactName("*m)a&n^y%i££n+v!a:l[i]d"),
690+
"manyinvalid"
691+
);
692+
});

src/actions-util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,3 +709,7 @@ export async function isAnalyzingDefaultBranch(): Promise<boolean> {
709709

710710
return currentRef === defaultBranch;
711711
}
712+
713+
export function sanitizeArifactName(name: string): string {
714+
return name.replace(/[^a-zA-Z0-9_\\-]+/g, "");
715+
}

src/analyze-action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ async function uploadDebugArtifacts(toUpload: string[], rootDir: string) {
244244
suffix += `-${entry[1]}`;
245245
}
246246
await artifact.create().uploadArtifact(
247-
`${DEBUG_ARTIFACT_NAME}${suffix}`,
247+
actionsUtil.sanitizeArifactName(`${DEBUG_ARTIFACT_NAME}${suffix}`),
248248
toUpload.map((file) => path.normalize(file)),
249249
path.normalize(rootDir)
250250
);

0 commit comments

Comments
 (0)