@@ -320,9 +320,23 @@ jQuery(document).ready(function($) {
320
320
return str ;
321
321
}
322
322
323
+ var utf8btoa = function ( str )
324
+ {
325
+ // see https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
326
+ var binstr = '' ;
327
+ ( new TextEncoder ( ) ) . encode ( str ) . forEach ( byte => binstr += String . fromCharCode ( byte ) ) ;
328
+ return btoa ( binstr ) ;
329
+ } ;
330
+
331
+ var utf8atob = function ( str )
332
+ {
333
+ // see https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
334
+ return ( new TextDecoder ( ) ) . decode ( Uint8Array . from ( atob ( str ) , c => c . charCodeAt ( 0 ) ) ) ;
335
+ } ;
336
+
323
337
var base64urldecode = function ( data )
324
338
{
325
- return window . atob ( strtr ( data , { '.' : '+' , '_' : '/' } ) . padEnd ( data . length % 4 , '=' ) ) ;
339
+ return utf8atob ( strtr ( data , { '.' : '+' , '_' : '/' } ) . padEnd ( data . length % 4 , '=' ) ) ;
326
340
}
327
341
328
342
var getPdfFieldData = function ( id )
@@ -549,7 +563,7 @@ jQuery(document).ready(function($) {
549
563
var updatePluginDataField = function ( )
550
564
{
551
565
// we can't use json directly, we have to use encoding without slashes and quotes due to an unnecessary stripslashes() call in wpforms/includes/admin/builder/panels/class-base.php
552
- data_tag . val ( btoa ( JSON . stringify ( pluginData ) ) ) ;
566
+ data_tag . val ( utf8btoa ( JSON . stringify ( pluginData ) ) ) ;
553
567
}
554
568
555
569
var getAttachments = function ( )
@@ -777,7 +791,7 @@ jQuery(document).ready(function($) {
777
791
var data_base64 = data_tag . val ( ) ;
778
792
var data_json = null ;
779
793
var data = { } ;
780
- try { if ( data_base64 ) data_json = atob ( data_base64 ) ; }
794
+ try { if ( data_base64 ) data_json = utf8atob ( data_base64 ) ; }
781
795
catch ( e ) { data_json = data_base64 ; }
782
796
try { if ( data_json ) data = JSON . parse ( data_json ) ; }
783
797
catch ( e ) { return errorMessage ( e . message ) ; }
0 commit comments