From cd8d40af1ae755ca7c889f3aa1b6c3d8d0c14dd7 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Mon, 2 Feb 2026 22:40:14 +0100 Subject: [PATCH] chore: robustify playground decode (#17606) For some reason LLMs like to percent-encode stuff, this makes the download script still run in that case --- playgrounds/sandbox/scripts/download.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/playgrounds/sandbox/scripts/download.js b/playgrounds/sandbox/scripts/download.js index e3c862cb61..538b4956fe 100644 --- a/playgrounds/sandbox/scripts/download.js +++ b/playgrounds/sandbox/scripts/download.js @@ -635,7 +635,19 @@ if (is_local) { } else if (url && url.origin === 'https://svelte.dev' && url.pathname.startsWith('/playground/')) { // Svelte playground URL handling (existing logic) if (url.hash.length > 1) { - const decoded = atob(url.hash.slice(1).replaceAll('-', '+').replaceAll('_', '/')); + // Decode percent-encoded characters (e.g., %5F => _), and replace base64 chars. + let decoded; + try { + // First, decode URI components to handle %xx encodings (e.g. %5F -> _) (LLMs calling this script sometimes encode them for some reason) + decoded = url.hash.slice(1); + decoded = decodeURIComponent(decoded); + + // Now, restore for base64 (replace -/+, _/ /) + decoded = atob(decoded.replaceAll('-', '+').replaceAll('_', '/')); + } catch (e) { + console.error('Failed to decode URL hash:', e); + process.exit(1); + } // putting it directly into the blob gives a corrupted file const u8 = new Uint8Array(decoded.length); for (let i = 0; i < decoded.length; i++) {