Validate domain format on site creation

pull/427/head
Uku Taht 6 years ago
parent b724def948
commit d71e40f16f

@ -22,6 +22,7 @@ defmodule Plausible.Site do
site
|> cast(attrs, [:domain, :timezone])
|> validate_required([:domain, :timezone])
|> validate_format(:domain, ~r/^[a-zA-z0-9\-\.\/\:]*$/, message: "only letters, numbers, slashes and period allowed")
|> unique_constraint(:domain)
|> clean_domain
end

@ -52,6 +52,18 @@ defmodule PlausibleWeb.SiteControllerTest do
assert html_response(conn, 200) =~ "can't be blank"
end
test "only alphanumeric characters and slash allowed in domain", %{conn: conn} do
conn =
post(conn, "/sites", %{
"site" => %{
"timezone" => "Europe/London",
"domain" => "!@£.com"
}
})
assert html_response(conn, 200) =~ "only letters, numbers, slashes and period allowed"
end
test "renders form again when it is a duplicate domain", %{conn: conn} do
insert(:site, domain: "example.com")

Loading…
Cancel
Save