Adjustment for parsing non-ICANN domain mentions

This commit is contained in:
mint 2022-10-04 23:22:24 +00:00 committed by Sam Therapy
parent 1e612ac3a3
commit c77d40de20
Signed by: sam
GPG key ID: 4D8B07C18F31ACBD

View file

@ -45,7 +45,7 @@ defmodule Linkify.Parser do
@tlds "./priv/tlds.txt"
|> File.read!()
|> String.split("\n", trim: true)
|> Enum.concat(["onion"])
|> Enum.concat(["onion", "i2p", "loki", "ygg"])
|> MapSet.new()
@default_opts %{
@ -205,7 +205,7 @@ defmodule Linkify.Parser do
def check_and_link(:mention, buffer, opts, user_acc) do
buffer
|> match_mention
|> match_mention(opts)
|> link_mention(buffer, opts, user_acc)
end
@ -362,7 +362,7 @@ defmodule Linkify.Parser do
|> Kernel.!()
end
def match_mention(buffer) do
def match_mention(buffer, opts) do
case Regex.run(~r/^@(?<user>[a-zA-Z\d_-]+)(@(?<host>[^@]+))?$/, buffer,
capture: [:user, :host]
) do
@ -370,7 +370,7 @@ defmodule Linkify.Parser do
"@" <> user
[user, hostname] ->
if valid_hostname?(hostname) && valid_tld?(hostname, []),
if valid_hostname?(hostname) && (valid_tld?(hostname, opts) || ip?(hostname)),
do: "@" <> user <> "@" <> hostname,
else: nil