logo

auto_linker

AutoLinker-shim, based on https://git.pleroma.social/pleroma/auto_linker
commit: c00c4e75b35367fa42c95ffd9b8c455bf9995829
parent: 90613b4bae875a3610c275b7056b61ffdd53210d
Author: Egor <egor@kislitsyn.com>
Date:   Wed,  1 May 2019 07:53:15 +0000

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

Fix tld validation

Closes #4

See merge request pleroma/auto_linker!15

Diffstat:

Mlib/auto_linker/parser.ex14++++++++------
Mtest/parser_test.exs13+++++++++++++
2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/lib/auto_linker/parser.ex b/lib/auto_linker/parser.ex @@ -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 diff --git a/test/parser_test.exs b/test/parser_test.exs @@ -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