Skip to content

Commit 4bbfb2a

Browse files
JonasKruckenbergLms24AbhiPrasad
authored
fix(utils): accept DSN URLs with empty password (#5902)
Co-authored-by: Lukas Stracke <[email protected]> Co-authored-by: Abhijeet Prasad <[email protected]>
1 parent 47e8b7a commit 4bbfb2a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/utils/src/dsn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DsnComponents, DsnLike, DsnProtocol } from '@sentry/types';
33
import { SentryError } from './error';
44

55
/** Regular expression used to parse a Dsn. */
6-
const DSN_REGEX = /^(?:(\w+):)\/\/(?:(\w+)(?::(\w+))?@)([\w.-]+)(?::(\d+))?\/(.+)/;
6+
const DSN_REGEX = /^(?:(\w+):)\/\/(?:(\w+)(?::(\w+)?)?@)([\w.-]+)(?::(\d+))?\/(.+)/;
77

88
function isValidProtocol(protocol?: string): protocol is DsnProtocol {
99
return protocol === 'http' || protocol === 'https';

packages/utils/test/dsn.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ describe('Dsn', () => {
120120
expect(dsn.projectId).toBe('321');
121121
});
122122

123+
test('parses a Dsn with empty password', () => {
124+
const dsn = makeDsn('https://abc:@sentry.io/123/321');
125+
expect(dsn.protocol).toBe('https');
126+
expect(dsn.publicKey).toBe('abc');
127+
expect(dsn.pass).toBe('');
128+
expect(dsn.host).toBe('sentry.io');
129+
expect(dsn.port).toBe('');
130+
expect(dsn.path).toBe('123');
131+
expect(dsn.projectId).toBe('321');
132+
});
133+
123134
test('with a long path', () => {
124135
const dsn = makeDsn('https://[email protected]/sentry/custom/installation/321');
125136
expect(dsn.protocol).toBe('https');

0 commit comments

Comments
 (0)