From 3fcbb92238f9a373d9ff355665260f5631811397 Mon Sep 17 00:00:00 2001 From: James Maa Date: Thu, 26 Dec 2024 22:18:33 -0800 Subject: [PATCH] Avoid using `URL.canParse` (#1701) * Avoid using canParse * Ignore bad url --- ext/js/data/anki-note-builder.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ext/js/data/anki-note-builder.js b/ext/js/data/anki-note-builder.js index 7586516ad..11f6ea041 100644 --- a/ext/js/data/anki-note-builder.js +++ b/ext/js/data/anki-note-builder.js @@ -82,8 +82,13 @@ export class AnkiNoteBuilder { } // Make URL field blank if URL source is Yomitan - if (URL.canParse(context.url) && new URL(context.url).protocol === new URL(import.meta.url).protocol) { - context.url = ''; + try { + const url = new URL(context.url); + if (url.protocol === new URL(import.meta.url).protocol) { + context.url = ''; + } + } catch (e) { + // Ignore } const commonData = this._createData(dictionaryEntry, mode, context, resultOutputMode, glossaryLayoutMode, compactTags, media, dictionaryStylesMap);