From f622bc7eb95f28e9cf38b7520825f397d881c0c6 Mon Sep 17 00:00:00 2001 From: Hauke D Date: Wed, 10 Jul 2024 10:18:12 +0000 Subject: [PATCH] Handle decodeURIComponent errors --- src/main.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index a91c77d..3160354 100644 --- a/src/main.ts +++ b/src/main.ts @@ -151,7 +151,13 @@ window.addEventListener('DOMContentLoaded', async () => { const search_from_url = () => { let what = '' if (window.location.hash.startsWith('#q=')) { - what = decodeURIComponent(window.location.hash.substring('#q='.length)).trim() + try { + what = decodeURIComponent(window.location.hash.substring('#q='.length)).trim() + } + catch (error) { + // for example, `decodeURIComponent('%97')` causes "URIError: malformed URI sequence" + console.log('ignoring bad window.location.hash',error) + } } search_term.value = what do_search(what)