Skip to content

Commit

Permalink
fix(pgs): handle empty filepaths in calc_route
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Jan 9, 2025
1 parent 6530b86 commit facce22
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pgs/calc_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,11 @@ func genRedirectRoute(actual string, fromStr string, to string) string {

func calcRoutes(projectName, fp string, userRedirects []*RedirectRule) []*HttpReply {
rts := []*HttpReply{}
if fp == "" {
fp = "/"
}
// add route as-is without expansion
if fp != "" && !strings.HasSuffix(fp, "/") {
if !strings.HasSuffix(fp, "/") {
defRoute := shared.GetAssetFileName(&utils.FileEntry{
Filepath: filepath.Join(projectName, fp),
})
Expand Down
36 changes: 36 additions & 0 deletions pgs/calc_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,42 @@ func TestCalcRoutes(t *testing.T) {
{Filepath: "test/404.html", Status: 404},
},
},
{
Name: "redirect-root-full-url",
Actual: calcRoutes(
"test",
"/",
[]*RedirectRule{
{
From: "/*",
To: "https://pico.sh",
Status: 301,
},
},
),
Expected: []*HttpReply{
{Filepath: "test/index.html", Status: 200},
{Filepath: "https://pico.sh", Status: 301},
},
},
{
Name: "redirect-empty-route-full-url",
Actual: calcRoutes(
"test",
"",
[]*RedirectRule{
{
From: "/*",
To: "https://pico.sh",
Status: 301,
},
},
),
Expected: []*HttpReply{
{Filepath: "test/index.html", Status: 200},
{Filepath: "https://pico.sh", Status: 301},
},
},
{
Name: "redirect-full-url-directory",
Actual: calcRoutes(
Expand Down

0 comments on commit facce22

Please sign in to comment.