From 3f6c2a6674bd80e932add0348984b9e35386ac9c Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Sat, 19 Apr 2025 12:29:49 -0500 Subject: [PATCH] encode the hash seperately from the rest of url --- src/client/location.ts | 2 +- src/shared/rewriters/url.ts | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/client/location.ts b/src/client/location.ts index 50143c8..d85e9d3 100644 --- a/src/client/location.ts +++ b/src/client/location.ts @@ -55,7 +55,7 @@ export function createLocationProxy( if (prop === "hash") { self.location.hash = args[0]; const ev = new UrlChangeEvent(client.url.href); - if (client.frame) client.frame.dispatchEvent(ev); + if (!client.isSubframe) client.frame?.dispatchEvent(ev); return; } diff --git a/src/shared/rewriters/url.ts b/src/shared/rewriters/url.ts index 6a558fe..055585b 100644 --- a/src/shared/rewriters/url.ts +++ b/src/shared/rewriters/url.ts @@ -46,14 +46,15 @@ export function rewriteUrl(url: string | URL, meta: URLMeta) { if (base.startsWith("about:")) base = unrewriteUrl(self.location.href); // jank!!!!! weird jank!!! const realUrl = tryCanParseURL(url, base); if (!realUrl) return url; - const hash = realUrl.hash; + const encodedHash = $scramjet.codec.encode(realUrl.hash.slice(1)); realUrl.hash = ""; return ( location.origin + $scramjet.config.prefix + $scramjet.codec.encode(realUrl.href) + - hash + "#" + + encodedHash ); } } @@ -75,11 +76,14 @@ export function unrewriteUrl(url: string | URL) { return url.substring(prefixed.length); } else if (url.startsWith("mailto:") || url.startsWith("about:")) { return url; - } else if (tryCanParseURL(url)) { - return $scramjet.codec.decode( - url.slice((location.origin + $scramjet.config.prefix).length) - ); } else { - return url; + const realUrl = tryCanParseURL(url); + if (!realUrl) return url; + const decodedHash = $scramjet.codec.decode(realUrl.hash.slice(1)); + realUrl.hash = ""; + + return $scramjet.codec.decode( + realUrl.href.slice(prefixed.length) + "#" + decodedHash + ); } }