From c00221f218ea28931a840bd8fb00920ca2a43e7d Mon Sep 17 00:00:00 2001 From: Alexander Bartsch Date: Mon, 15 Aug 2022 10:58:30 +0200 Subject: [PATCH] consider slashes while cleaning labels fix prettier format check errors --- src/utilities/workflowAnnotationUtils.test.ts | 5 +++++ src/utilities/workflowAnnotationUtils.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/utilities/workflowAnnotationUtils.test.ts b/src/utilities/workflowAnnotationUtils.test.ts index 5fc55475b..bed2bd1a8 100644 --- a/src/utilities/workflowAnnotationUtils.test.ts +++ b/src/utilities/workflowAnnotationUtils.test.ts @@ -11,5 +11,10 @@ describe('WorkflowAnnotationUtils', () => { ) expect(cleanLabel('with⚒️emoji')).toEqual('withemoji') }) + it('should remove slashes from label', () => { + expect( + cleanLabel('Workflow Name / With Slashes / And Spaces') + ).toEqual('Workflow_Name_-_With_Slashes_-_And_Spaces') + }) }) }) diff --git a/src/utilities/workflowAnnotationUtils.ts b/src/utilities/workflowAnnotationUtils.ts index 8d3045946..248b53f33 100644 --- a/src/utilities/workflowAnnotationUtils.ts +++ b/src/utilities/workflowAnnotationUtils.ts @@ -37,7 +37,11 @@ export function getWorkflowAnnotationKeyLabel(): string { * @returns cleaned label */ export function cleanLabel(label: string): string { - const removedInvalidChars = label.replace(/[^-A-Za-z0-9_.]/gi, '') + let removedInvalidChars = label + .replace(/\s/gi, '_') + .replace(/[\/\\\|]/gi, '-') + .replace(/[^-A-Za-z0-9_.]/gi, '') + const regex = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/ return regex.exec(removedInvalidChars)[0] || '' }