Skip to content

Commit

Permalink
fix(utils): accept DSN URLs with empty password (#5902)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
Co-authored-by: Abhijeet Prasad <aprasad@sentry.io>
  • Loading branch information
3 people committed Oct 7, 2022
1 parent 47e8b7a commit 4bbfb2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/utils/src/dsn.ts
Expand Up @@ -3,7 +3,7 @@ import { DsnComponents, DsnLike, DsnProtocol } from '@sentry/types';
import { SentryError } from './error';

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

function isValidProtocol(protocol?: string): protocol is DsnProtocol {
return protocol === 'http' || protocol === 'https';
Expand Down
11 changes: 11 additions & 0 deletions packages/utils/test/dsn.test.ts
Expand Up @@ -120,6 +120,17 @@ describe('Dsn', () => {
expect(dsn.projectId).toBe('321');
});

test('parses a Dsn with empty password', () => {
const dsn = makeDsn('https://abc:@sentry.io/123/321');
expect(dsn.protocol).toBe('https');
expect(dsn.publicKey).toBe('abc');
expect(dsn.pass).toBe('');
expect(dsn.host).toBe('sentry.io');
expect(dsn.port).toBe('');
expect(dsn.path).toBe('123');
expect(dsn.projectId).toBe('321');
});

test('with a long path', () => {
const dsn = makeDsn('https://abc@sentry.io/sentry/custom/installation/321');
expect(dsn.protocol).toBe('https');
Expand Down

0 comments on commit 4bbfb2a

Please sign in to comment.