Commit c00c4e75 authored by minibikini's avatar minibikini

Merge branch 'fix/tld-validation' into 'master'

Fix tld validation

Closes #4

See merge request pleroma/auto_linker!15
parents 90613b4b 0e6869c9
Pipeline #11302 passed with stages
in 1 minute and 31 seconds
......@@ -338,13 +338,15 @@ defmodule AutoLinker.Parser do
end
def is_valid_tld?(true, buffer) do
[host] = Regex.run(@match_hostname, buffer, capture: [:host])
if is_ip?(host) do
true
with [host] <- Regex.run(@match_hostname, buffer, capture: [:host]) do
if is_ip?(host) do
true
else
tld = host |> String.split(".") |> List.last()
MapSet.member?(@tlds, tld)
end
else
tld = host |> String.split(".") |> List.last()
MapSet.member?(@tlds, tld)
_ -> false
end
end
......
......@@ -110,6 +110,19 @@ defmodule AutoLinker.ParserTest do
text = "google.com"
assert parse(text, url: false, phone: true) == text
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
def valid_number?([list], number) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment