From 3eda1b9ed8822bf548e18e436ad2521c28d622ed Mon Sep 17 00:00:00 2001 From: Eric Bower Date: Fri, 10 Jan 2025 09:33:12 -0500 Subject: [PATCH] fix(pgs): add forward slash to prefix of filepath for calc_route --- pgs/calc_route.go | 4 ++-- pgs/calc_route_test.go | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pgs/calc_route.go b/pgs/calc_route.go index 1f1bfebd..347fb069 100644 --- a/pgs/calc_route.go +++ b/pgs/calc_route.go @@ -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, "/") { diff --git a/pgs/calc_route_test.go b/pgs/calc_route_test.go index 8989f9ff..bdeaac0d 100644 --- a/pgs/calc_route_test.go +++ b/pgs/calc_route_test.go @@ -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 {