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 {
67
67
return undefined ;
68
68
}
69
69
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 ;
72
79
} catch ( e ) {
73
80
logger . error ( 'Failed to extract url from DSN' , e ) ;
74
81
return undefined ;
Original file line number Diff line number Diff line change @@ -345,21 +345,15 @@ describe('Tests the SDK functionality', () => {
345
345
expect ( result ) . toBeNull ( ) ;
346
346
} ) ;
347
347
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' , ( ) => {
349
349
( getDevServer as jest . Mock ) . mockReturnValue ( { url : 'http://localhost:8081' } ) ;
350
350
351
351
const mockBeforeBreadcrumb = ( breadcrumb : Breadcrumb , _hint ?: BreadcrumbHint ) => {
352
352
return breadcrumb ;
353
353
} ;
354
354
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
-
361
355
const passedOptions = {
362
- dsn :
'https://[email protected] /1234567 ' ,
356
+ dsn : 'invalid-dsn ' ,
363
357
beforeBreadcrumb : mockBeforeBreadcrumb ,
364
358
} ;
365
359
@@ -373,9 +367,6 @@ describe('Tests the SDK functionality', () => {
373
367
const result = usedOptions ( ) ?. beforeBreadcrumb ! ( breadcrumb ) ;
374
368
375
369
expect ( result ) . toEqual ( breadcrumb ) ;
376
-
377
- // Restore the original URL constructor
378
- ( global as any ) . URL = originalURL ;
379
370
} ) ;
380
371
381
372
it ( 'should keep non dev server or dsn breadcrumbs' , ( ) => {
You can’t perform that action at this time.
0 commit comments