Skip to content

Commit

Permalink
fix(pgs): add forward slash to prefix of filepath for calc_route
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Jan 10, 2025
1 parent a942011 commit 3eda1b9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pgs/calc_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ func genRedirectRoute(actual string, fromStr string, to string) string {

func calcRoutes(projectName, fp string, userRedirects []*RedirectRule) []*HttpReply {
rts := []*HttpReply{}
if fp == "" {
fp = "/"
if !strings.HasPrefix(fp, "/") {
fp = "/" + fp
}
// add route as-is without expansion
if !strings.HasSuffix(fp, "/") {
Expand Down
20 changes: 20 additions & 0 deletions pgs/calc_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,26 @@ func TestCalcRoutes(t *testing.T) {
{Filepath: "public/404.html", Status: 404},
},
},
{
Name: "implicit-prefix-slash-redirect",
Actual: calcRoutes(
"public",
"software/scripts",
[]*RedirectRule{
{
From: "/software/concat/*",
To: "/software/scripts/:splat",
Status: 301,
},
},
),
Expected: []*HttpReply{
{Filepath: "public/software/scripts", Status: 200},
{Filepath: "public/software/scripts.html", Status: 200},
{Filepath: "/software/scripts/", Status: 301},
{Filepath: "public/404.html", Status: 404},
},
},
}

for _, fixture := range fixtures {
Expand Down

0 comments on commit 3eda1b9

Please sign in to comment.