- commit
- e3ce3b9
- parent
- 6a7c21b
- author
- Eric Bower
- date
- 2024-12-25 13:51:00 -0500 EST
fix(pgs): wildcard with splat suffix
2 files changed,
+48,
-2
+10,
-2
1@@ -86,7 +86,7 @@ func correlatePlaceholder(orig, pattern string) (string, string) {
2 if strings.HasPrefix(item, ":") {
3 nextList = append(nextList, origList[idx])
4 } else if strings.Contains(item, "*") {
5- nextList = append(nextList, strings.ReplaceAll(item, "*", "(.+)"))
6+ nextList = append(nextList, strings.ReplaceAll(item, "*", "(.*)"))
7 } else if item == origList[idx] {
8 nextList = append(nextList, origList[idx])
9 }
10@@ -151,16 +151,24 @@ func genRedirectRoute(actual string, fromStr string, to string) string {
11 if len(item) > 1 {
12 ls = actualList[idx+1:]
13 }
14+ // standalone splat
15 splat := strings.Join(ls, "/")
16 mapper[":splat"] = splat
17+
18+ // splat as a suffix to a string
19+ place := strings.ReplaceAll(item, "*", ":splat")
20+ mapper[place] = strings.Join(actualList[idx:], "/")
21 break
22 }
23 }
24
25 fin := []string{"/"}
26
27+ fmt.Println(toList)
28 for _, item := range toList {
29- if item == ":splat" {
30+ fmt.Println(item)
31+ if strings.HasSuffix(item, ":splat") {
32+ fmt.Println(mapper[item])
33 fin = append(fin, mapper[item])
34 } else if mapper[item] != "" {
35 fin = append(fin, mapper[item])
+38,
-0
1@@ -512,6 +512,44 @@ func TestCalcRoutes(t *testing.T) {
2 {Filepath: "https://super.fly.sh/super/ficial.html", Status: 302},
3 },
4 },
5+ {
6+ Name: "well-known-splat-suffix",
7+ Actual: calcRoutes(
8+ "public",
9+ "/.well-known/nodeinfo",
10+ []*RedirectRule{
11+ {
12+ From: "/.well-known/nodeinfo*",
13+ To: "https://some.dev/.well-known/nodeinfo:splat",
14+ Status: 301,
15+ },
16+ },
17+ ),
18+ Expected: []*HttpReply{
19+ {Filepath: "public/.well-known/nodeinfo", Status: 200},
20+ {Filepath: "public/.well-known/nodeinfo.html", Status: 200},
21+ {Filepath: "https://some.dev/.well-known/nodeinfo", Status: 301},
22+ },
23+ },
24+ {
25+ Name: "wildcard-query-param",
26+ Actual: calcRoutes(
27+ "public",
28+ "/.well-known/webfinger?query=nice",
29+ []*RedirectRule{
30+ {
31+ From: "/.well-known/webfinger*",
32+ To: "https://some.dev/.well-known/webfinger:splat",
33+ Status: 301,
34+ },
35+ },
36+ ),
37+ Expected: []*HttpReply{
38+ {Filepath: "public/.well-known/webfinger?query=nice", Status: 200},
39+ {Filepath: "public/.well-known/webfinger?query=nice.html", Status: 200},
40+ {Filepath: "https://some.dev/.well-known/webfinger?query=nice", Status: 301},
41+ },
42+ },
43 }
44
45 for _, fixture := range fixtures {