diff --git a/src/util.ts b/src/util.ts index ddf25f7..19e8719 100644 --- a/src/util.ts +++ b/src/util.ts @@ -5,7 +5,7 @@ export function postProcessMarkdown(md: string): string { } export function sanitize(str: string): string { - return (str || '').replace(/[/\\:*?"<>|]/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 60); + return (str || '').replace(/[/\\:*?"<>|#^\[\]]/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 60); } // Guard for URLs we fetch on behalf of the client (covers, thumbnails): only diff --git a/tests/util.test.ts b/tests/util.test.ts index aa69f57..d893c39 100644 --- a/tests/util.test.ts +++ b/tests/util.test.ts @@ -31,6 +31,11 @@ describe('sanitize', () => { test('returns empty string for undefined input', () => { expect(sanitize(undefined as any)).toBe(''); }); + test('strips Obsidian-reserved chars [ ] # ^ common in video titles', () => { + expect(sanitize('[Official Video] Song')).toBe('Official Video Song'); + expect(sanitize('C# tutorial')).toBe('C tutorial'); + expect(sanitize('Video [4K] ^best^')).toBe('Video 4K best'); + }); }); describe('extractVideoId', () => {