Merge pull request #3683 from gitbutlerapp/Update-branch-normalize-function

Update the normalizeBranchName function to match rust
This commit is contained in:
Kiril Videlov 2024-05-03 14:23:18 -07:00 committed by GitHub
commit 3bfc081b94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -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');
});
});

View File

@ -1,3 +1,3 @@
export function normalizeBranchName(value: string) {
return value.replace(/[^0-9a-z/_.]+/g, '-');
return value.replace(/[^A-Za-z0-9_/.#]+/g, '-');
}