diff --git a/internal/pkg/describe/uri.go b/internal/pkg/describe/uri.go index a03800291c4..22dd57d3f63 100644 --- a/internal/pkg/describe/uri.go +++ b/internal/pkg/describe/uri.go @@ -5,6 +5,7 @@ package describe import ( "fmt" + "regexp" "strings" "github.com/aws/copilot-cli/internal/pkg/term/color" @@ -403,14 +404,17 @@ func (u *LBWebServiceURI) String() string { func (u *accessURI) strings() []string { var uris []string + re := regexp.MustCompile("/+") for _, dnsName := range u.DNSNames { protocol := "http://" if u.HTTPS { protocol = "https://" } path := "" - if u.Path != "/" { + if !strings.HasPrefix(u.Path, "/") { path = fmt.Sprintf("/%s", u.Path) + } else if u.Path != "/" { + path = re.ReplaceAllString(u.Path, "/") } uris = append(uris, color.HighlightResource(protocol+dnsName+path)) } diff --git a/internal/pkg/describe/uri_test.go b/internal/pkg/describe/uri_test.go index 58d460aab82..2b5c2d5e5ed 100644 --- a/internal/pkg/describe/uri_test.go +++ b/internal/pkg/describe/uri_test.go @@ -6,9 +6,10 @@ package describe import ( "errors" "fmt" - "github.com/aws/copilot-cli/internal/pkg/aws/ecs" "testing" + "github.com/aws/copilot-cli/internal/pkg/aws/ecs" + "github.com/aws/copilot-cli/internal/pkg/deploy/cloudformation/stack" "github.com/aws/copilot-cli/internal/pkg/describe/mocks" "github.com/aws/copilot-cli/internal/pkg/template" @@ -680,6 +681,24 @@ func TestLBWebServiceURI_String(t *testing.T) { wanted: "http://jobs.test.phonetool.com", }, + "http with /v2 path": { + accessDNSNames: []string{"jobs.test.phonetool.com"}, + accessPath: "/v2", + + wanted: "http://jobs.test.phonetool.com/v2", + }, + "http with multiple slash path": { + accessDNSNames: []string{"jobs.test.phonetool.com"}, + accessPath: "//v2", + + wanted: "http://jobs.test.phonetool.com/v2", + }, + "http with non-root path": { + accessDNSNames: []string{"jobs.test.phonetool.com"}, + accessPath: "v2", + + wanted: "http://jobs.test.phonetool.com/v2", + }, "cloudfront": { accessDNSNames: []string{"abc.cloudfront.net"}, accessPath: "svc", @@ -707,6 +726,27 @@ func TestLBWebServiceURI_String(t *testing.T) { wanted: "https://jobs.test.phonetool.com", }, + "https with /v2 path": { + accessDNSNames: []string{"jobs.test.phonetool.com"}, + accessPath: "/v2", + accessHTTPS: true, + + wanted: "https://jobs.test.phonetool.com/v2", + }, + "https with multiple slash path": { + accessDNSNames: []string{"jobs.test.phonetool.com"}, + accessPath: "//v2", + accessHTTPS: true, + + wanted: "https://jobs.test.phonetool.com/v2", + }, + "https with non-root path": { + accessDNSNames: []string{"jobs.test.phonetool.com"}, + accessPath: "v2", + accessHTTPS: true, + + wanted: "https://jobs.test.phonetool.com/v2", + }, } for name, tc := range testCases {