diff --git a/CHANGELOG.md b/CHANGELOG.md
index 38112a98b..144394dc1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,6 +38,7 @@ All notable changes to this project will be documented in this file.
- Alert outgrown enterprise users of their usage plausible/analytics#2197
- Manually lock and unlock enterprise users plausible/analytics#2197
- ARM64 support for docker images plausible/analytics#2103
+- Add support for international domain names (IDNs) plausible/analytics#2034
### Fixed
- Hash part of the URL can now be used when excluding pages with `script.exclusions.hash.js`.
diff --git a/lib/plausible/site/schema.ex b/lib/plausible/site/schema.ex
index cac81039e..699d2e1a0 100644
--- a/lib/plausible/site/schema.ex
+++ b/lib/plausible/site/schema.ex
@@ -43,14 +43,15 @@ defmodule Plausible.Site do
site
|> cast(attrs, [:domain, :timezone])
|> validate_required([:domain, :timezone])
- |> validate_format(:domain, ~r/^[a-zA-Z0-9\-\.\/\:]*$/,
+ |> clean_domain()
+ |> validate_format(:domain, ~r/^[-\.\\\/:\p{L}\d]*$/u,
message: "only letters, numbers, slashes and period allowed"
)
+ |> validate_domain_reserved_characters()
|> unique_constraint(:domain,
message:
"This domain has already been taken. Perhaps one of your team members registered it? If that's not the case, please contact support@plausible.io"
)
- |> clean_domain
end
def make_public(site) do
@@ -114,4 +115,20 @@ defmodule Plausible.Site do
domain: clean_domain
})
end
+
+ # https://tools.ietf.org/html/rfc3986#section-2.2
+ @uri_reserved_chars ~w(: ? # [ ] @ ! $ & ' \( \) * + , ; =)
+ defp validate_domain_reserved_characters(changeset) do
+ domain = get_field(changeset, :domain) || ""
+
+ if String.contains?(domain, @uri_reserved_chars) do
+ add_error(
+ changeset,
+ :domain,
+ "must not contain URI reserved characters #{@uri_reserved_chars}"
+ )
+ else
+ changeset
+ end
+ end
end
diff --git a/lib/plausible_web/templates/site/settings_visibility.html.eex b/lib/plausible_web/templates/site/settings_visibility.html.eex
index 44f4a63de..96b159018 100644
--- a/lib/plausible_web/templates/site/settings_visibility.html.eex
+++ b/lib/plausible_web/templates/site/settings_visibility.html.eex
@@ -7,21 +7,25 @@
<% end %>
- <%= if @site.public do %>
-