- commit
- a942011
- parent
- 3c2cdad
- author
- Eric Bower
- date
- 2025-01-10 07:50:04 -0500 EST
fix(pgs): infinite redirect with 404
2 files changed,
+29,
-1
+9,
-1
1@@ -89,6 +89,14 @@ func correlatePlaceholder(orig, pattern string) (string, string) {
2 nextList = append(nextList, strings.ReplaceAll(item, "*", "(.*)"))
3 } else if item == origList[idx] {
4 nextList = append(nextList, origList[idx])
5+ } else {
6+ nextList = append(nextList, item)
7+ // if we are on the last pattern item then we need to ensure
8+ // it matches the end of string so partial matches are not counted
9+ if idx == len(patternList)-1 {
10+ // regex end of string matcher
11+ nextList = append(nextList, "$")
12+ }
13 }
14 }
15
16@@ -266,7 +274,7 @@ func calcRoutes(projectName, fp string, userRedirects []*RedirectRule) []*HttpRe
17 // we might have a directory so add a trailing slash with a 301
18 // we can't check for file extention because route could have a dot
19 // and ext parsing gets confused
20- if fp != "" && !strings.HasSuffix(fp, "/") {
21+ if !strings.HasSuffix(fp, "/") {
22 redirectRoute := shared.GetAssetFileName(&utils.FileEntry{
23 Filepath: fp + "/",
24 })
+20,
-0
1@@ -604,6 +604,26 @@ func TestCalcRoutes(t *testing.T) {
2 {Filepath: "public/404.html", Status: 404},
3 },
4 },
5+ {
6+ Name: "non-match-dont-redirect",
7+ Actual: calcRoutes(
8+ "public",
9+ "/scripts/asd",
10+ []*RedirectRule{
11+ {
12+ From: "/concat/*",
13+ To: "/scripts/:splat",
14+ Status: 301,
15+ },
16+ },
17+ ),
18+ Expected: []*HttpReply{
19+ {Filepath: "public/scripts/asd", Status: 200},
20+ {Filepath: "public/scripts/asd.html", Status: 200},
21+ {Filepath: "/scripts/asd/", Status: 301},
22+ {Filepath: "public/404.html", Status: 404},
23+ },
24+ },
25 }
26
27 for _, fixture := range fixtures {