Skip to content

Commit 178afce

Browse files
committed
fix(mobileconfig): too many underscores for the file name
1 parent df1e291 commit 178afce

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/lib/mobileconfig/export.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import type { MobileConfigExportResult, MobileConfigGenerationOptions } from '$t
77
import { downloadFile } from '$utils/misc';
88

99
export const getMobileConfigFileName = (account: Pick<Account, 'name'>) => {
10-
const safeName = account.name.replace(/[^a-z0-9]/gi, '_').toLowerCase();
11-
return `${safeName}_caldav${MOBILE_CONFIG_EXTENSION}`;
10+
const safeName = account.name
11+
.replace(/[^a-z0-9]+/gi, '_')
12+
.replace(/^_+|_+$/g, '')
13+
.toLowerCase();
14+
return `${safeName ? `${safeName}_` : ''}caldav${MOBILE_CONFIG_EXTENSION}`;
1215
};
1316

1417
const isSaveDialogCancellation = (error: unknown) => {

src/tests/lib/mobileconfig/index.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ describe('mobileconfig core helpers', () => {
2222

2323
it('creates a filesystem-safe export filename', () => {
2424
expect(getMobileConfigFileName({ name: 'Work & Personal' })).toBe(
25-
'work___personal_caldav.mobileconfig',
25+
'work_personal_caldav.mobileconfig',
2626
);
27+
expect(getMobileConfigFileName({ name: 'chloe (fastmail)' })).toBe(
28+
'chloe_fastmail_caldav.mobileconfig',
29+
);
30+
expect(getMobileConfigFileName({ name: '✨' })).toBe('caldav.mobileconfig');
2731
});
2832
});

0 commit comments

Comments
 (0)