Skip to content

Commit

Permalink
Handle decodeURIComponent errors
Browse files Browse the repository at this point in the history
  • Loading branch information
haukex committed Jul 10, 2024
1 parent 276b379 commit f622bc7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f622bc7

Please sign in to comment.