Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider slashes while cleaning labels #231

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/utilities/workflowAnnotationUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
})
6 changes: 5 additions & 1 deletion src/utilities/workflowAnnotationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] || ''
}