@@ -21,15 +21,27 @@ function encodeURL(str) {
2121
2222function decodeURL ( str ) {
2323 // restore base64 format
24- const base64 = str . replace ( / - / g, "+" ) . replace ( / _ / g, "/" ) ;
25- const binary = atob ( base64 ) ;
26- const bytes = new Uint8Array ( binary . length ) ;
27-
28- for ( let i = 0 ; i < binary . length ; i ++ ) {
29- bytes [ i ] = binary . charCodeAt ( i ) ;
24+ try {
25+
26+ const base64 = str . replace ( / - / g, "+" ) . replace ( / _ / g, "/" ) ;
27+ const binary = atob ( base64 ) ;
28+ const bytes = new Uint8Array ( binary . length ) ;
29+
30+ for ( let i = 0 ; i < binary . length ; i ++ ) {
31+ bytes [ i ] = binary . charCodeAt ( i ) ;
32+ }
33+
34+ return pako . inflate ( bytes , { to : "string" } ) ;
35+ } catch ( e ) {
36+ return decodeBase64URL ( str ) ;
3037 }
31-
32- return pako . inflate ( bytes , { to : "string" } ) ;
38+ }
39+
40+ const decodeBase64URL = ( str ) => {
41+ const base64 = str . replaceAll ( '-' , '+' ) . replaceAll ( '_' , '/' ) ;
42+ const binary = atob ( base64 ) ;
43+ const bytes = Uint8Array . from ( binary , ( m ) => m . codePointAt ( 0 ) ) ;
44+ return new TextDecoder ( ) . decode ( bytes ) ;
3345}
3446
3547// const testString = 'helljkh"ao⛳❤️🧀';
0 commit comments