@@ -120,13 +120,13 @@ type GlobalWithBase64Helpers = {
120
120
* @returns A base64-encoded version of the string
121
121
*/
122
122
export function unicodeToBase64 ( plaintext : string ) : string {
123
- const globalObject = getGlobalObject ( ) as GlobalWithBase64Helpers ;
123
+ const globalObject = getGlobalObject < GlobalWithBase64Helpers > ( ) ;
124
124
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
128
if ( typeof plaintext !== 'string' ) {
129
- throw new Error ( `Input must be a string. Received input of type ${ typeof plaintext } .` ) ;
129
+ throw new Error ( `Input must be a string. Received input of type ' ${ typeof plaintext } ' .` ) ;
130
130
}
131
131
132
132
// browser
@@ -157,10 +157,10 @@ export function unicodeToBase64(plaintext: string): string {
157
157
throw new SentryError ( 'Neither `window.btoa` nor `global.Buffer` is defined.' ) ;
158
158
} catch ( err ) {
159
159
// Cast to a string just in case we're given something else
160
- const stringifiedInput = String ( plaintext ) ;
160
+ const stringifiedInput = JSON . stringify ( plaintext ) ;
161
161
const errMsg = `Unable to convert to base64: ${
162
- stringifiedInput . length > 256 ? `${ stringifiedInput . slice ( 0 , 256 ) } ...` : stringifiedInput
163
- } `;
162
+ stringifiedInput ? .length > 256 ? `${ stringifiedInput . slice ( 0 , 256 ) } ...` : stringifiedInput
163
+ } . `;
164
164
throw new SentryError ( `${ errMsg } \nGot error: ${ err } ` ) ;
165
165
}
166
166
}
@@ -173,14 +173,14 @@ export function unicodeToBase64(plaintext: string): string {
173
173
* @returns A Unicode string
174
174
*/
175
175
export function base64ToUnicode ( base64String : string ) : string {
176
- const globalObject = getGlobalObject ( ) as GlobalWithBase64Helpers ;
176
+ const globalObject = getGlobalObject < GlobalWithBase64Helpers > ( ) ;
177
177
178
178
// To account for the fact that different platforms use different character encodings natively, our `tracestate` spec
179
179
// calls for all jsonified data to be encoded in UTF-8 bytes before being passed to the base64 encoder. So to reverse
180
180
// the process, decode from base64 to bytes, then feed those bytes to a UTF-8 decoder.
181
181
try {
182
182
if ( typeof base64String !== 'string' ) {
183
- throw new Error ( `Input must be a string. Received input of type ${ typeof base64String } .` ) ;
183
+ throw new Error ( `Input must be a string. Received input of type ' ${ typeof base64String } ' .` ) ;
184
184
}
185
185
186
186
// browser
@@ -210,10 +210,10 @@ export function base64ToUnicode(base64String: string): string {
210
210
throw new SentryError ( 'Neither `window.atob` nor `global.Buffer` is defined.' ) ;
211
211
} catch ( err ) {
212
212
// we cast to a string just in case we're given something else
213
- const stringifiedInput = String ( base64String ) ;
213
+ const stringifiedInput = JSON . stringify ( base64String ) ;
214
214
const errMsg = `Unable to convert from base64: ${
215
- stringifiedInput . length > 256 ? `${ stringifiedInput . slice ( 0 , 256 ) } ...` : stringifiedInput
216
- } `;
215
+ stringifiedInput ? .length > 256 ? `${ stringifiedInput . slice ( 0 , 256 ) } ...` : stringifiedInput
216
+ } . `;
217
217
throw new SentryError ( `${ errMsg } \nGot error: ${ err } ` ) ;
218
218
}
219
219
}
0 commit comments