File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,10 @@ export function unicodeToBase64(plaintext: string): string {
125
125
// To account for the fact that different platforms use different character encodings natively, our `tracestate`
126
126
// spec calls for all jsonified data to be encoded in UTF-8 bytes before being passed to the base64 encoder.
127
127
try {
128
+ if ( typeof plaintext !== 'string' ) {
129
+ throw new Error ( `Input must be a string. Received input of type ${ typeof plaintext } .` ) ;
130
+ }
131
+
128
132
// browser
129
133
if ( 'btoa' in globalObject ) {
130
134
// encode using UTF-8
@@ -175,6 +179,10 @@ export function base64ToUnicode(base64String: string): string {
175
179
// calls for all jsonified data to be encoded in UTF-8 bytes before being passed to the base64 encoder. So to reverse
176
180
// the process, decode from base64 to bytes, then feed those bytes to a UTF-8 decoder.
177
181
try {
182
+ if ( typeof base64String !== 'string' ) {
183
+ throw new Error ( `Input must be a string. Received input of type ${ typeof base64String } .` ) ;
184
+ }
185
+
178
186
// browser
179
187
if ( 'atob' in globalObject ) {
180
188
// `atob` returns a string rather than bytes, so we first need to encode using the native encoding (UTF-16)
You can’t perform that action at this time.
0 commit comments