Skip to content

Commit 1c78eff

Browse files
committed
instantsearch.js: Avoid error when hash is absent
instantsearch.js:29 Uncaught TypeError: Cannot read properties of null (reading '1') at instantsearch.js:29:65 at instantsearch.js:229:3
1 parent 12bed64 commit 1c78eff

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

docs/js/instantsearch.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
},
2727
}
2828
}
29-
const search_query = doc.location.hash.match(/q=(.*?)(&|$)/)[1] ?? '';
29+
let match = null;
30+
const search_query = (match = doc.location.hash.match(/q=(.*?)(&|$)/)) ? match[1] : '';
3031
const parsed_search_query = decodeURI(search_query.replace('+', ' '));
31-
const search_page = doc.location.hash.match(/p=(\d*?)(&|$)/)[1] ?? 1;
32+
const search_page = (match = doc.location.hash.match(/p=(\d*?)(&|$)/)) ? match[1] : 1;
3233
const parsed_search_page = parseInt(search_page);
3334
const version = doc.location.pathname.split('/')[2];
3435
const search = instantsearch({

0 commit comments

Comments
 (0)