Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Trim trailing whitespace from pathname

Uku Taht102ff1885e92
diff --git a/lib/plausible_web/controllers/api/external_controller.ex b/lib/plausible_web/controllers/api/external_controller.ex
index 6ed4a0771f..c01be7ab9c 100644
--- a/lib/plausible_web/controllers/api/external_controller.ex
+++ b/lib/plausible_web/controllers/api/external_controller.ex
@@ -271,6 +271,7 @@ defmodule PlausibleWeb.Api.ExternalController do
pathname =
(uri.path || "/")
|> URI.decode()
+ |> String.trim_trailing()
if hash_mode && uri.fragment do
pathname <> "#" <> URI.decode(uri.fragment)
diff --git a/test/plausible_web/controllers/api/external_controller_test.exs b/test/plausible_web/controllers/api/external_controller_test.exs
index 3eab7e1a85..cd345e1367 100644
--- a/test/plausible_web/controllers/api/external_controller_test.exs
+++ b/test/plausible_web/controllers/api/external_controller_test.exs
@@ -141,6 +141,21 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do
assert pageview.pathname == "/"
end
+ test "trailing whitespace is removed", %{conn: conn} do
+ params = %{
+ name: "pageview",
+ url: "http://www.example.com/path ",
+ domain: "external-controller-test-trailing-whitespace.com"
+ }
+
+ conn
+ |> post("/api/event", params)
+
+ pageview = get_event("external-controller-test-trailing-whitespace.com")
+
+ assert pageview.pathname == "/path"
+ end
+
test "bots and crawlers are ignored", %{conn: conn} do
params = %{
name: "pageview",