From 97c407b0b74f77acded8a396207d6865e973a64c Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Tue, 10 Dec 2024 13:10:17 +0000 Subject: [PATCH] Escape filenames in URLs --- src/lib/common/files.ts | 2 +- src/pages/SketchSchemes.svelte | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/common/files.ts b/src/lib/common/files.ts index 76823b0b..7b15f152 100644 --- a/src/lib/common/files.ts +++ b/src/lib/common/files.ts @@ -26,7 +26,7 @@ export function getEditUrl( filename: string, schema: Schema, ): string { - return `scheme.html?authority=${authority}&schema=${schema}&file=${filename}`; + return `scheme.html?authority=${authority}&schema=${schema}&file=${encodeURIComponent(filename)}`; } // Returns a list of filenames and the detected schema diff --git a/src/pages/SketchSchemes.svelte b/src/pages/SketchSchemes.svelte index ae52bcde..56d543a6 100644 --- a/src/pages/SketchSchemes.svelte +++ b/src/pages/SketchSchemes.svelte @@ -36,13 +36,13 @@ let params = new URLSearchParams(window.location.search); // If the authority is invalid, it'll be handled in onMount asynchronously let authority = params.get("authority") || ""; - let filename = params.get("file") || ""; + let filename = decodeURIComponent(params.get("file") || ""); if (window.localStorage.getItem(getKey(authority, filename)) == null) { // If either the filename or authority is wrong, redirect to the very first // page. This might be annoying if the authority is correct, but it's // simpler. Unless a user copies a bad URL, this shouldn't happen anyway - window.location.href = `choose_area.html?schema=${$schema}&error=File ${filename} in authority ${authority} not found`; + window.location.href = `choose_area.html?schema=${$schema}&error=File ${encodeURIComponent(filename)} in authority ${authority} not found`; } mapStyle.set(params.get("style") || "streets");