Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(utils): accept DSN URLs with empty password #5902

Merged
merged 4 commits into from Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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+))?\/(.+)/;
Fixed Show fixed Hide fixed
JonasKruckenberg marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -119,6 +119,17 @@ describe('Dsn', () => {
expect(dsn.path).toBe('123');
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');
Expand Down