File tree Expand file tree Collapse file tree 2 files changed +11
-13
lines changed Expand file tree Collapse file tree 2 files changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -67,8 +67,15 @@ export function init(passedOptions: ReactNativeOptions): void {
6767 return undefined ;
6868 }
6969 try {
70- const url = new URL ( dsn ) ;
71- return `${ url . protocol } //${ url . host } ` ;
70+ const regex = / ^ ( h t t p s ? ) : \/ \/ (?: [ ^ @ ] + @ ) ? ( [ ^ / ] + ) (?: \/ .* ) ? $ / ;
71+ const matches = dsn . match ( regex ) ;
72+
73+ if ( matches ) {
74+ const [ , protocol , host ] = matches ;
75+ return `${ protocol } ://${ host } ` ;
76+ }
77+ logger . error ( 'Failed to extract url from DSN: ' , dsn ) ;
78+ return undefined ;
7279 } catch ( e ) {
7380 logger . error ( 'Failed to extract url from DSN' , e ) ;
7481 return undefined ;
Original file line number Diff line number Diff line change @@ -345,21 +345,15 @@ describe('Tests the SDK functionality', () => {
345345 expect ( result ) . toBeNull ( ) ;
346346 } ) ;
347347
348- it ( 'should keep breadcrumbs matching dsn if the url parsing fails for dsn' , ( ) => {
348+ it ( 'should keep breadcrumbs if the url parsing fails for dsn' , ( ) => {
349349 ( getDevServer as jest . Mock ) . mockReturnValue ( { url : 'http://localhost:8081' } ) ;
350350
351351 const mockBeforeBreadcrumb = ( breadcrumb : Breadcrumb , _hint ?: BreadcrumbHint ) => {
352352 return breadcrumb ;
353353 } ;
354354
355- // Mock the URL constructor to throw an exception for this test case
356- const originalURL = ( global as any ) . URL ;
357- jest . spyOn ( global as any , 'URL' ) . mockImplementationOnce ( ( ) => {
358- throw new Error ( 'Failed to parse DSN URL' ) ;
359- } ) ;
360-
361355 const passedOptions = {
362- dsn :
'https://[email protected] /1234567 ' , 356+ dsn : 'invalid-dsn ' ,
363357 beforeBreadcrumb : mockBeforeBreadcrumb ,
364358 } ;
365359
@@ -373,9 +367,6 @@ describe('Tests the SDK functionality', () => {
373367 const result = usedOptions ( ) ?. beforeBreadcrumb ! ( breadcrumb ) ;
374368
375369 expect ( result ) . toEqual ( breadcrumb ) ;
376-
377- // Restore the original URL constructor
378- ( global as any ) . URL = originalURL ;
379370 } ) ;
380371
381372 it ( 'should keep non dev server or dsn breadcrumbs' , ( ) => {
You can’t perform that action at this time.
0 commit comments