From f7f63eac9a665f207863541aad914dffab781115 Mon Sep 17 00:00:00 2001 From: Iris Clawd Date: Fri, 19 Jun 2026 22:58:18 +0000 Subject: [PATCH] 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. --- docs/safari-anchor-fix.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/safari-anchor-fix.js b/docs/safari-anchor-fix.js index 9b579c114..ef54effd4 100644 --- a/docs/safari-anchor-fix.js +++ b/docs/safari-anchor-fix.js @@ -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();