Skip to content

Commit

Permalink
Merge pull request #427 from plausible/invalid-domain
Browse files Browse the repository at this point in the history
Validate domain format on site creation
  • Loading branch information
ukutaht authored Nov 19, 2020
2 parents b724def + 1548b41 commit 3c76678
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file.
- Ignore automated browsers (Phantom, Selenium, Headless Chrome, etc)
- Display domain's favicon on the home page
- Ignore consecutive pageviews on same pathname plausible/analytics#417
- Validate domain format on site creation plausible/analytics#427

### Fixed
- Do not error when activating an already activated account plausible/analytics#370
Expand Down
1 change: 1 addition & 0 deletions lib/plausible/site/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/plausible_web/controllers/site_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 3c76678

Please sign in to comment.