@@ -120,13 +120,13 @@ type GlobalWithBase64Helpers = {
120120 * @returns A base64-encoded version of the string
121121 */
122122export function unicodeToBase64 ( plaintext : string ) : string {
123- const globalObject = getGlobalObject ( ) as GlobalWithBase64Helpers ;
123+ const globalObject = getGlobalObject < GlobalWithBase64Helpers > ( ) ;
124124
125125 // To account for the fact that different platforms use different character encodings natively, our `tracestate`
126126 // spec calls for all jsonified data to be encoded in UTF-8 bytes before being passed to the base64 encoder.
127127 try {
128128 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 } ' .` ) ;
130130 }
131131
132132 // browser
@@ -157,10 +157,10 @@ export function unicodeToBase64(plaintext: string): string {
157157 throw new SentryError ( 'Neither `window.btoa` nor `global.Buffer` is defined.' ) ;
158158 } catch ( err ) {
159159 // Cast to a string just in case we're given something else
160- const stringifiedInput = String ( plaintext ) ;
160+ const stringifiedInput = JSON . stringify ( plaintext ) ;
161161 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+ } . `;
164164 throw new SentryError ( `${ errMsg } \nGot error: ${ err } ` ) ;
165165 }
166166}
@@ -173,14 +173,14 @@ export function unicodeToBase64(plaintext: string): string {
173173 * @returns A Unicode string
174174 */
175175export function base64ToUnicode ( base64String : string ) : string {
176- const globalObject = getGlobalObject ( ) as GlobalWithBase64Helpers ;
176+ const globalObject = getGlobalObject < GlobalWithBase64Helpers > ( ) ;
177177
178178 // To account for the fact that different platforms use different character encodings natively, our `tracestate` spec
179179 // calls for all jsonified data to be encoded in UTF-8 bytes before being passed to the base64 encoder. So to reverse
180180 // the process, decode from base64 to bytes, then feed those bytes to a UTF-8 decoder.
181181 try {
182182 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 } ' .` ) ;
184184 }
185185
186186 // browser
@@ -210,10 +210,10 @@ export function base64ToUnicode(base64String: string): string {
210210 throw new SentryError ( 'Neither `window.atob` nor `global.Buffer` is defined.' ) ;
211211 } catch ( err ) {
212212 // we cast to a string just in case we're given something else
213- const stringifiedInput = String ( base64String ) ;
213+ const stringifiedInput = JSON . stringify ( base64String ) ;
214214 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+ } . `;
217217 throw new SentryError ( `${ errMsg } \nGot error: ${ err } ` ) ;
218218 }
219219}
0 commit comments