Skip to content

Commit ae42fd8

Browse files
authored
fix: uri root path checking (#5778)
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License. This config will display `Your service is accessible at https://my-domain.com//v2` after deploy successfully. ```yaml http: path: '/v2' ``` This PR fix this.
1 parent eae7ae7 commit ae42fd8

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

internal/pkg/describe/uri.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package describe
55

66
import (
77
"fmt"
8+
"regexp"
89
"strings"
910

1011
"github.com/aws/copilot-cli/internal/pkg/term/color"
@@ -403,14 +404,17 @@ func (u *LBWebServiceURI) String() string {
403404

404405
func (u *accessURI) strings() []string {
405406
var uris []string
407+
re := regexp.MustCompile("/+")
406408
for _, dnsName := range u.DNSNames {
407409
protocol := "http://"
408410
if u.HTTPS {
409411
protocol = "https://"
410412
}
411413
path := ""
412-
if u.Path != "/" {
414+
if !strings.HasPrefix(u.Path, "/") {
413415
path = fmt.Sprintf("/%s", u.Path)
416+
} else if u.Path != "/" {
417+
path = re.ReplaceAllString(u.Path, "/")
414418
}
415419
uris = append(uris, color.HighlightResource(protocol+dnsName+path))
416420
}

internal/pkg/describe/uri_test.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ package describe
66
import (
77
"errors"
88
"fmt"
9-
"github.com/aws/copilot-cli/internal/pkg/aws/ecs"
109
"testing"
1110

11+
"github.com/aws/copilot-cli/internal/pkg/aws/ecs"
12+
1213
"github.com/aws/copilot-cli/internal/pkg/deploy/cloudformation/stack"
1314
"github.com/aws/copilot-cli/internal/pkg/describe/mocks"
1415
"github.com/aws/copilot-cli/internal/pkg/template"
@@ -680,6 +681,24 @@ func TestLBWebServiceURI_String(t *testing.T) {
680681

681682
wanted: "http://jobs.test.phonetool.com",
682683
},
684+
"http with /v2 path": {
685+
accessDNSNames: []string{"jobs.test.phonetool.com"},
686+
accessPath: "/v2",
687+
688+
wanted: "http://jobs.test.phonetool.com/v2",
689+
},
690+
"http with multiple slash path": {
691+
accessDNSNames: []string{"jobs.test.phonetool.com"},
692+
accessPath: "//v2",
693+
694+
wanted: "http://jobs.test.phonetool.com/v2",
695+
},
696+
"http with non-root path": {
697+
accessDNSNames: []string{"jobs.test.phonetool.com"},
698+
accessPath: "v2",
699+
700+
wanted: "http://jobs.test.phonetool.com/v2",
701+
},
683702
"cloudfront": {
684703
accessDNSNames: []string{"abc.cloudfront.net"},
685704
accessPath: "svc",
@@ -707,6 +726,27 @@ func TestLBWebServiceURI_String(t *testing.T) {
707726

708727
wanted: "https://jobs.test.phonetool.com",
709728
},
729+
"https with /v2 path": {
730+
accessDNSNames: []string{"jobs.test.phonetool.com"},
731+
accessPath: "/v2",
732+
accessHTTPS: true,
733+
734+
wanted: "https://jobs.test.phonetool.com/v2",
735+
},
736+
"https with multiple slash path": {
737+
accessDNSNames: []string{"jobs.test.phonetool.com"},
738+
accessPath: "//v2",
739+
accessHTTPS: true,
740+
741+
wanted: "https://jobs.test.phonetool.com/v2",
742+
},
743+
"https with non-root path": {
744+
accessDNSNames: []string{"jobs.test.phonetool.com"},
745+
accessPath: "v2",
746+
accessHTTPS: true,
747+
748+
wanted: "https://jobs.test.phonetool.com/v2",
749+
},
710750
}
711751

712752
for name, tc := range testCases {

0 commit comments

Comments
 (0)