Skip to content

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

Allow underscores in site domain names (#6182)

Adrian Gruntkowski779f286b7065
diff --git a/lib/plausible/site.ex b/lib/plausible/site.ex
index 9a3d9729d7..f7c76f589b 100644
--- a/lib/plausible/site.ex
+++ b/lib/plausible/site.ex
@@ -208,8 +208,8 @@ defmodule Plausible.Site do
end
defp validate_domain_format(changeset) do
- validate_format(changeset, :domain, ~r/^[-\.\\\/:\p{L}\d]*$/u,
- message: "only letters, numbers, slashes and period allowed"
+ validate_format(changeset, :domain, ~r/^[-\.\\\/_:\p{L}\d]*$/u,
+ message: "only letters, numbers, slashes, underscores and period allowed"
)
end
diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exs
index c3b32fc564..f047a51a7e 100644
--- a/test/plausible_web/controllers/site_controller_test.exs
+++ b/test/plausible_web/controllers/site_controller_test.exs
@@ -463,7 +463,21 @@ defmodule PlausibleWeb.SiteControllerTest do
}
})
- assert html_response(conn, 200) =~ "only letters, numbers, slashes and period allowed"
+ assert html_response(conn, 200) =~
+ "only letters, numbers, slashes, underscores and period allowed"
+ end
+
+ test "underscores are allowed in the domain", %{conn: conn} do
+ conn =
+ post(conn, "/sites", %{
+ "site" => %{
+ "timezone" => "Europe/London",
+ "domain" => "example.com/some_blog_site"
+ }
+ })
+
+ assert redirected_to(conn) ==
+ "/example.com%2Fsome_blog_site/installation?site_created=true&flow="
end
test "renders form again when it is a duplicate domain", %{conn: conn} do
diff --git a/test/plausible_web/live/change_domain_test.exs b/test/plausible_web/live/change_domain_test.exs
index 18ef42a876..df5b7428c7 100644
--- a/test/plausible_web/live/change_domain_test.exs
+++ b/test/plausible_web/live/change_domain_test.exs
@@ -161,7 +161,7 @@ defmodule PlausibleWeb.Live.ChangeDomainTest do
|> element("form")
|> render_submit(%{site: %{domain: "invalid domain with spaces"}})
- assert html =~ "only letters, numbers, slashes and period allowed"
+ assert html =~ "only letters, numbers, slashes, underscores and period allowed"
end
test "renders back to settings link with correct path", %{conn: conn, site: site} do