fix: strip Obsidian-reserved chars [ ] # ^ from filenames

Titles like '[Official Video]' or 'C#' produced names Obsidian rejects
or that break the ![[...]] embed syntax.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
liyachen 2026-07-18 17:45:01 -04:00
parent 7f5d9f15cc
commit 362cddf39d
2 changed files with 6 additions and 1 deletions

View file

@ -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

View file

@ -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', () => {