Browse Source

Fix tld validation

merge-requests/15/head
Egor Kislitsyn 5 years ago
parent
commit
0e6869c9ea
2 changed files with 21 additions and 6 deletions
  1. +8
    -6
      lib/auto_linker/parser.ex
  2. +13
    -0
      test/parser_test.exs

+ 8
- 6
lib/auto_linker/parser.ex View File

@ -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


+ 13
- 0
test/parser_test.exs View File

@ -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


Loading…
Cancel
Save