Skip to content

Commit

Permalink
Prevent lone surrogates in file names from breaking AnkiConnect
Browse files Browse the repository at this point in the history
  • Loading branch information
killergerbah committed Jun 29, 2024
1 parent 01cf6d0 commit be4c1d5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions common/anki/anki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { AnkiSettings } from '@project/common/settings';
import sanitize from 'sanitize-filename';
import { extractText, sourceString } from '@project/common/util';

declare global {
interface String {
toWellFormed?: () => string;
}
}

const ankiQuerySpecialCharacters = ['"', '*', '_', '\\', ':'];
const alphaNumericCharacters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

Expand Down Expand Up @@ -384,6 +390,10 @@ export class Anki {
}

private _sanitizeFileName(name: string) {
if (typeof name.toWellFormed === 'function') {
name = name.toWellFormed();
}

return sanitize(name, { replacement: '_' });
}

Expand Down

0 comments on commit be4c1d5

Please sign in to comment.