fix some url rewriters

This commit is contained in:
Percs 2024-07-15 00:41:43 -05:00
parent 39f11ef812
commit f53bc623ff
3 changed files with 3 additions and 18 deletions

View file

@ -12,7 +12,6 @@ import "./storage.ts";
import "./css.ts"; import "./css.ts";
import "./history.ts"; import "./history.ts";
import "./worker.ts"; import "./worker.ts";
import "./url.ts";
import "./beacon.ts" import "./beacon.ts"
declare global { declare global {

View file

@ -1,13 +0,0 @@
import { encodeUrl } from "../shared/rewriters/url";
export const URL = globalThis.URL;
if (globalThis.window) {
window.URL = new Proxy(URL, {
construct(target, argArray, newTarget) {
if (typeof argArray[0] === "string") argArray[0] = encodeUrl(argArray[0]);
if (typeof argArray[1] === "string") argArray[1] = encodeUrl(argArray[1]);
return Reflect.construct(target, argArray, newTarget);
},
});
}

View file

@ -1,5 +1,4 @@
import { URL } from "../../client/url"; ;import { rewriteJs } from "./js";
import { rewriteJs } from "./js";
function canParseUrl(url: string, origin?: URL) { function canParseUrl(url: string, origin?: URL) {
try { try {
@ -14,7 +13,7 @@ function canParseUrl(url: string, origin?: URL) {
// something is broken with this but i didn't debug it // something is broken with this but i didn't debug it
export function encodeUrl(url: string | URL, origin?: URL) { export function encodeUrl(url: string | URL, origin?: URL) {
if (url instanceof URL) { if (url instanceof URL) {
return url.toString(); url = url.href;
} }
if (!origin) { if (!origin) {
@ -46,7 +45,7 @@ export function encodeUrl(url: string | URL, origin?: URL) {
// something is also broken with this but i didn't debug it // something is also broken with this but i didn't debug it
export function decodeUrl(url: string | URL) { export function decodeUrl(url: string | URL) {
if (url instanceof URL) { if (url instanceof URL) {
return url.toString(); url = url.href;
} }
if (/^(#|about|data|mailto|javascript)/.test(url)) { if (/^(#|about|data|mailto|javascript)/.test(url)) {