Skip to content

Commit

Permalink
fix(proxy): don't replace -[0-9] with :[0-9] in domain name
Browse files Browse the repository at this point in the history
  • Loading branch information
paullaffitte committed Aug 2, 2023
1 parent 4b6aef1 commit a027d4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,13 @@ func recoveryMiddleware() gin.HandlerFunc {
}

func handleOriginRegistryPort(originRegistry string) string {
re := regexp.MustCompile(`-([0-9]+)`)
re := regexp.MustCompile(`-([0-9]+)$`)
parts := re.FindStringSubmatch(originRegistry)
originRegistryBytes := []byte(originRegistry)

if len(parts) == 2 {
originRegistry = strings.ReplaceAll(originRegistry, parts[0], ":"+parts[1])
originRegistryBytes = re.ReplaceAll(originRegistryBytes, []byte(":$1"))
}

return originRegistry
return string(originRegistryBytes)
}
11 changes: 11 additions & 0 deletions internal/proxy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ func Test_handleOriginRegistryPort(t *testing.T) {
originRegistry: "enix.io-5000",
expectedOutput: "enix.io:5000",
},
{
name: "Domain name with number + port",
originRegistry: "regsitry-2.enix.io-5000",
expectedOutput: "regsitry-2.enix.io:5000",
},

{
name: "Domain name with number + port with same value",
originRegistry: "regsitry-5000.enix.io-5000",
expectedOutput: "regsitry-5000.enix.io:5000",
},
}

g := NewWithT(t)
Expand Down

0 comments on commit a027d4d

Please sign in to comment.