File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
playgrounds/sandbox/scripts Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -635,7 +635,19 @@ if (is_local) {
635635} else if ( url && url . origin === 'https://svelte.dev' && url . pathname . startsWith ( '/playground/' ) ) {
636636 // Svelte playground URL handling (existing logic)
637637 if ( url . hash . length > 1 ) {
638- const decoded = atob ( url . hash . slice ( 1 ) . replaceAll ( '-' , '+' ) . replaceAll ( '_' , '/' ) ) ;
638+ // Decode percent-encoded characters (e.g., %5F => _), and replace base64 chars.
639+ let decoded ;
640+ try {
641+ // First, decode URI components to handle %xx encodings (e.g. %5F -> _) (LLMs calling this script sometimes encode them for some reason)
642+ decoded = url . hash . slice ( 1 ) ;
643+ decoded = decodeURIComponent ( decoded ) ;
644+
645+ // Now, restore for base64 (replace -/+, _/ /)
646+ decoded = atob ( decoded . replaceAll ( '-' , '+' ) . replaceAll ( '_' , '/' ) ) ;
647+ } catch ( e ) {
648+ console . error ( 'Failed to decode URL hash:' , e ) ;
649+ process . exit ( 1 ) ;
650+ }
639651 // putting it directly into the blob gives a corrupted file
640652 const u8 = new Uint8Array ( decoded . length ) ;
641653 for ( let i = 0 ; i < decoded . length ; i ++ ) {
You can’t perform that action at this time.
0 commit comments