no longer using blank string for failed regex

This commit is contained in:
Jaiveer Katariya
2022-12-12 15:26:34 -05:00
parent 86aca609b9
commit 0b82897af3
2 changed files with 4 additions and 2 deletions
@@ -18,7 +18,7 @@ describe('WorkflowAnnotationUtils', () => {
})
it('should return a blank string when regex fails (https://github.com/Azure/k8s-deploy/issues/266)', () => {
const label = '持续部署'
expect(cleanLabel(label)).toEqual('')
expect(cleanLabel(label)).toEqual('github-workflow-file')
let removedInvalidChars = label
.replace(/\s/gi, '_')
+3 -1
View File
@@ -43,6 +43,8 @@ export function cleanLabel(label: string): string {
.replace(/[^-A-Za-z0-9_.]/gi, '')
const regex = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/
const regexResult = regex.exec(removedInvalidChars) || ['']
const regexResult = regex.exec(removedInvalidChars) || [
'github-workflow-file'
]
return regexResult[0]
}