mirror of
https://github.com/plausible/analytics.git
synced 2024-09-11 18:07:33 +03:00
Improve domain cleanup on site creation (#3393)
This commit is contained in:
parent
296637dc18
commit
d608fec903
@ -221,12 +221,12 @@ defmodule Plausible.Site do
|
||||
defp clean_domain(changeset) do
|
||||
clean_domain =
|
||||
(get_field(changeset, :domain) || "")
|
||||
|> String.downcase()
|
||||
|> String.trim()
|
||||
|> String.replace_leading("http://", "")
|
||||
|> String.replace_leading("https://", "")
|
||||
|> String.trim("/")
|
||||
|> String.replace_leading("www.", "")
|
||||
|> String.replace_trailing("/", "")
|
||||
|> String.downcase()
|
||||
|
||||
change(changeset, %{domain: clean_domain})
|
||||
end
|
||||
|
@ -235,17 +235,19 @@ defmodule PlausibleWeb.SiteControllerTest do
|
||||
assert Repo.get_by(Plausible.Site, domain: "example.com")
|
||||
end
|
||||
|
||||
test "cleans up the url", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, "/sites", %{
|
||||
"site" => %{
|
||||
"domain" => "https://www.Example.com/",
|
||||
"timezone" => "Europe/London"
|
||||
}
|
||||
})
|
||||
for url <- ["https://Example.com/", "HTTPS://EXAMPLE.COM/", "/Example.com/", "//Example.com/"] do
|
||||
test "cleans up an url like #{url}", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, "/sites", %{
|
||||
"site" => %{
|
||||
"domain" => unquote(url),
|
||||
"timezone" => "Europe/London"
|
||||
}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == "/example.com/snippet"
|
||||
assert Repo.get_by(Plausible.Site, domain: "example.com")
|
||||
assert redirected_to(conn) == "/example.com/snippet"
|
||||
assert Repo.get_by(Plausible.Site, domain: "example.com")
|
||||
end
|
||||
end
|
||||
|
||||
test "renders form again when domain is missing", %{conn: conn} do
|
||||
|
Loading…
Reference in New Issue
Block a user