Skip to content

Commit

Permalink
fix: fix DSN regex to handle port numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnu-deepsource committed Feb 2, 2024
1 parent 8a15f31 commit 76a5069
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion command/report/dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type DSN struct {
}

func NewDSN(raw string) (*DSN, error) {
dsnPattern := regexp.MustCompile(`^(https?)://([^:@]+)@([^:/]+)`)
var dsnPattern = regexp.MustCompile(`^(https?)://([^:@]+)@([^:/]+(?:\:\d+)?)`)
matches := dsnPattern.FindStringSubmatch(raw)
if len(matches) != 4 {
return nil, ErrInvalidDSN
Expand Down
11 changes: 11 additions & 0 deletions command/report/dsn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ func TestNewDSN(t *testing.T) {
},
wantErr: nil,
},
{
name: "valid DSN with port",
args: args{
raw: "http://f59a44307@localhost:8081",
},
want: &DSN{
Token: "f59a44307",
Host: "localhost:8081",
Protocol: "http",
},
},
{
name: "invalid DSN no http",
args: args{
Expand Down

0 comments on commit 76a5069

Please sign in to comment.