From 42d97b376a12a1d15f0ea7ae660f642e6e4893cb Mon Sep 17 00:00:00 2001 From: ike thecoder Date: Fri, 12 Apr 2024 15:37:28 -0700 Subject: [PATCH] convert space to dash for consumer tags (#1034) --- src/services/utils.ts | 2 +- src/test/services/utils.test.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/services/utils.ts b/src/services/utils.ts index f6411473a..7bcfb87d4 100644 --- a/src/services/utils.ts +++ b/src/services/utils.ts @@ -77,5 +77,5 @@ export async function fetchWithTimeout(resource: string, options: any = {}) { } export function alphanumericNoSpaces(str: string) { - return str.replace(/[^A-Za-z0-9:-]/gim, '').replace(/[:]/gim, '-'); + return str.replace(/[^A-Za-z0-9 :-]/gim, '').replace(/[ :]/gim, '-'); } diff --git a/src/test/services/utils.test.js b/src/test/services/utils.test.js index 9aa7fe164..e656c2d5a 100644 --- a/src/test/services/utils.test.js +++ b/src/test/services/utils.test.js @@ -1,15 +1,15 @@ import { alphanumericNoSpaces } from '../../services/utils'; describe('alphanumericNoSpaces tests', () => { - it('should remove spaces from the string', () => { + it('should replace space with dash in the string', () => { const input = 'hello world'; - const expectedOutput = 'helloworld'; + const expectedOutput = 'hello-world'; expect(alphanumericNoSpaces(input)).toEqual(expectedOutput); }); it('should remove special characters', () => { const input = 'hello@world!how%^&*are you?'; - const expectedOutput = 'helloworldhowareyou'; + const expectedOutput = 'helloworldhoware-you'; expect(alphanumericNoSpaces(input)).toEqual(expectedOutput); }); @@ -45,7 +45,7 @@ describe('alphanumericNoSpaces tests', () => { it('should handle string with mixed characters', () => { const input = 'hello!-world, how:are?you'; - const expectedOutput = 'hello-worldhow-areyou'; + const expectedOutput = 'hello-world-how-areyou'; expect(alphanumericNoSpaces(input)).toEqual(expectedOutput); }); });