From 63ee99b647df0965efd868e1d20c1ec38a95e5f8 Mon Sep 17 00:00:00 2001 From: Caleb Owens Date: Fri, 3 May 2024 20:09:22 +0100 Subject: [PATCH 1/2] Update the normalizeBranchName function to match rust Before, uppercase letters and hashes were missing from the regex. I've now coppied the regex from the rust code so they are now identical --- app/src/lib/utils/branch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/lib/utils/branch.ts b/app/src/lib/utils/branch.ts index eb03a7df0..9a226c3f5 100644 --- a/app/src/lib/utils/branch.ts +++ b/app/src/lib/utils/branch.ts @@ -1,3 +1,3 @@ export function normalizeBranchName(value: string) { - return value.replace(/[^0-9a-z/_.]+/g, '-'); + return value.replace(/[^A-Za-z0-9_/.#]+/g, '-'); } From 32a8992af683701621a0a91c2fa3d0e7058757d4 Mon Sep 17 00:00:00 2001 From: Caleb Owens Date: Fri, 3 May 2024 20:16:02 +0100 Subject: [PATCH 2/2] Add some basic test cases for normalizeBranchName --- app/src/lib/utils/branch.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 app/src/lib/utils/branch.test.ts diff --git a/app/src/lib/utils/branch.test.ts b/app/src/lib/utils/branch.test.ts new file mode 100644 index 000000000..896d695f8 --- /dev/null +++ b/app/src/lib/utils/branch.test.ts @@ -0,0 +1,16 @@ +import { normalizeBranchName } from '$lib/utils/branch'; +import { describe, expect, test } from 'vitest'; + +describe.concurrent('normalizeBranchName', () => { + test('it should remove undesirable symbols', () => { + expect(normalizeBranchName('a£^&*() b')).toEqual('a-b'); + }); + + test('it should preserve capital letters', () => { + expect(normalizeBranchName('Hello World')).toEqual('Hello-World'); + }); + + test('it should preserve `#`, `_`, `/`, and `.`', () => { + expect(normalizeBranchName('hello#_./world')).toEqual('hello#_./world'); + }); +});