Skip to content

Commit

Permalink
fixed :splat not being replaced when the matched rule when trailing s…
Browse files Browse the repository at this point in the history
…tring was not empty causing :splat to remain for host rules
  • Loading branch information
samvaughton committed Sep 29, 2021
1 parent dc9a08b commit c698400
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 1 addition & 5 deletions matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,5 @@ func replaceParams(to string, matched urlpath.Match) string {
}

func replaceSplat(to string, matched urlpath.Match) string {
if matched.Trailing != "" {
to = strings.ReplaceAll(to, ":splat", matched.Trailing)
}

return to
return strings.ReplaceAll(to, ":splat", matched.Trailing)
}
13 changes: 13 additions & 0 deletions matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestRedirects(t *testing.T) {
/accommodation/* /accommodation/ 200
http://one.test:2021/* http://two.test:2021/:splat
https://lch.k8.rentivo.com/* https://lakecomohomes.com/:splat
one.test:/2021/no-scheme two.test:2021/:splat
`))

Expand Down Expand Up @@ -96,6 +97,18 @@ func TestRedirects(t *testing.T) {
true,
"http://two.test:2021/redirect/foobar",
},
{
MustParseUrl("https://lch.k8.rentivo.com/example"),
true,
true,
"https://lakecomohomes.com/example",
},
{
MustParseUrl("https://lch.k8.rentivo.com/"),
true,
true,
"https://lakecomohomes.com/",
},
}

ctx := &MatchContext{
Expand Down

0 comments on commit c698400

Please sign in to comment.