From b05e27d0ac95dfe32e7bfbd2b8686446dccef8e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= Date: Mon, 2 May 2022 21:44:22 +0200 Subject: [PATCH] Combine paths with and without trailing slash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #269 Signed-off-by: Lukas Kämmerling --- pkg/api/collect.go | 2 +- pkg/api/collect_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/api/collect.go b/pkg/api/collect.go index 78666034..a285611c 100644 --- a/pkg/api/collect.go +++ b/pkg/api/collect.go @@ -207,7 +207,7 @@ func shouldCollect(r *http.Request) bool { } func parsePathname(p string) string { - return "/" + strings.TrimLeft(p, "/") + return "/" + strings.TrimLeft(strings.TrimRight(p, "/"), "/") } func parseHostname(r string) string { diff --git a/pkg/api/collect_test.go b/pkg/api/collect_test.go index 3ee03243..f4b3a52e 100644 --- a/pkg/api/collect_test.go +++ b/pkg/api/collect_test.go @@ -22,6 +22,9 @@ func TestParsePathname(t *testing.T) { if v := parsePathname("about"); v != "/about" { t.Errorf("error parsing pathname. expected %#v, got %#v", "/about", v) } + if v := parsePathname("about/"); v != "/about" { + t.Errorf("error parsing pathname. expected %#v, got %#v", "/about", v) + } } func TestParseHostname(t *testing.T) {