From efd97622985f1131889d4561f8a3ba0b061e896e Mon Sep 17 00:00:00 2001 From: tjpcc Date: Sat, 23 Sep 2023 13:18:30 -0600 Subject: improve shared host path handling --- contrib/sharedhost/replacement.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'contrib/sharedhost') diff --git a/contrib/sharedhost/replacement.go b/contrib/sharedhost/replacement.go index 9dc3a1e..cabc6b1 100644 --- a/contrib/sharedhost/replacement.go +++ b/contrib/sharedhost/replacement.go @@ -4,6 +4,7 @@ import ( "context" "crypto/tls" "net/url" + "path" sr "tildegit.org/tjp/sliderule" ) @@ -20,9 +21,9 @@ import ( func ReplaceTilde(replacement string) sr.Middleware { return func(inner sr.Handler) sr.Handler { return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { - if len(request.Path) > 1 && request.Path[0] == '/' && request.Path[1] == '~' { + if len(request.Path) > 1 && request.Path[0:2] == "/~" { request = cloneRequest(request) - request.Path = "/" + replacement + request.Path[2:] + request.Path = path.Clean("/" + replacement + request.Path[2:]) } return inner.Handle(ctx, request) -- cgit v1.2.3