Skip to content

Commit cf73983

Browse files
committed
fix: normalize derived domain
1 parent edfcf57 commit cf73983

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/algora/accounts/schemas/user.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ defmodule Algora.Accounts.User do
1111
alias Algora.MoneyUtils
1212
alias Algora.Organizations.Member
1313
alias Algora.Types.Money
14+
alias Algora.Util
1415
alias Algora.Workspace.Installation
1516
alias AlgoraWeb.Endpoint
1617

@@ -321,16 +322,16 @@ defmodule Algora.Accounts.User do
321322
def get_domain(%{"type" => type}) when type != "Organization", do: nil
322323

323324
def get_domain(%{"email" => email}) when is_binary(email) do
324-
domain = email |> String.split("@") |> List.last()
325+
domain = email |> String.split("@") |> List.last() |> Util.to_domain()
325326

326327
if not Algora.Crawler.blacklisted?(domain), do: domain
327328
end
328329

329330
def get_domain(%{"blog" => url}) when is_binary(url) do
330331
domain =
331-
with url when not is_nil(url) <- Algora.Util.normalize_url(url),
332+
with url when not is_nil(url) <- Util.normalize_url(url),
332333
%URI{host: host} when is_binary(host) and host != "" <- URI.parse(url) do
333-
host
334+
Util.to_domain(host)
334335
else
335336
_ -> nil
336337
end

lib/algora/shared/util.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ defmodule Algora.Util do
182182
end
183183
end
184184

185+
def to_domain(nil), do: nil
186+
187+
def to_domain(url) do
188+
url
189+
|> String.trim_leading("https://")
190+
|> String.trim_leading("http://")
191+
|> String.trim_leading("www.")
192+
end
193+
185194
def get_gravatar_url(email, opts \\ []) do
186195
default = Keyword.get(opts, :default, "")
187196
size = Keyword.get(opts, :size, 460)

0 commit comments

Comments
 (0)