chore: robustify playground decode (#17606)

For some reason LLMs like to percent-encode stuff, this makes the download script still run in that case
main
Simon H 16 hours ago committed by GitHub
parent 92e6721c03
commit cd8d40af1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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++) {

Loading…
Cancel
Save