fix: decode URL-encoded hash fragment before getElementById lookup

Anchors with special characters (e.g. spaces encoded as %20) would fail
the getElementById lookup because the raw URL-encoded string doesn't
match the element's id attribute. Apply decodeURIComponent() with a
try/catch fallback to handle malformed URIs gracefully.
This commit is contained in:
Iris Clawd
2026-06-19 22:58:18 +00:00
parent 6f5c99ed36
commit f7f63eac9a

View File

@@ -12,7 +12,13 @@
var hash = window.location.hash;
if (!hash) return;
var id = hash.substring(1);
var rawId = hash.substring(1);
var id;
try {
id = decodeURIComponent(rawId);
} catch (e) {
id = rawId;
}
var el = document.getElementById(id);
if (el) {
el.scrollIntoView();