Fix tld validation

This commit is contained in:
Egor Kislitsyn 2019-05-01 14:48:04 +07:00
parent 90613b4bae
commit 0e6869c9ea
2 changed files with 21 additions and 6 deletions

View file

@ -338,13 +338,15 @@ defmodule AutoLinker.Parser do
end end
def is_valid_tld?(true, buffer) do def is_valid_tld?(true, buffer) do
[host] = Regex.run(@match_hostname, buffer, capture: [:host]) with [host] <- Regex.run(@match_hostname, buffer, capture: [:host]) do
if is_ip?(host) do
if is_ip?(host) do true
true else
tld = host |> String.split(".") |> List.last()
MapSet.member?(@tlds, tld)
end
else else
tld = host |> String.split(".") |> List.last() _ -> false
MapSet.member?(@tlds, tld)
end end
end end

View file

@ -110,6 +110,19 @@ defmodule AutoLinker.ParserTest do
text = "google.com" text = "google.com"
assert parse(text, url: false, phone: true) == text assert parse(text, url: false, phone: true) == text
end end
test "do not link `:test.test`" do
text = ":test.test"
assert parse(text, %{
scheme: true,
extra: true,
class: false,
strip_prefix: false,
new_window: false,
rel: false
}) == text
end
end end
def valid_number?([list], number) do def valid_number?([list], number) do