logo

auto_linker

AutoLinker-shim, based on https://git.pleroma.social/pleroma/auto_linker git clone https://hacktivis.me/git/auto_linker.git
commit: 3ce2c34709c650a0315bda0f0683545626badfa3
parent 17126aa662de56f93f661e7767f7148e5b753234
Author: Mark Felder <feld@FreeBSD.org>
Date:   Thu, 19 Nov 2020 18:55:17 +0000

Fix linking URLs/domains with trailing punctuation

Diffstat:

Mlib/linkify/parser.ex4++--
Mtest/linkify_test.exs25+++++++++++++++++++++++--
2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/lib/linkify/parser.ex b/lib/linkify/parser.ex @@ -19,7 +19,7 @@ defmodule Linkify.Parser do @match_skipped_tag ~r/^(?<tag>(a|code|pre)).*>*/ - @delimiters ~r/[,.;:>]*$/ + @delimiters ~r/[,.;:>?!]*$/ @prefix_extra [ "magnet:?", @@ -249,7 +249,7 @@ defmodule Linkify.Parser do true true -> - tld = host |> String.trim_trailing(".") |> String.split(".") |> List.last() + tld = host |> strip_punctuation() |> String.split(".") |> List.last() MapSet.member?(@tlds, tld) end end diff --git a/test/linkify_test.exs b/test/linkify_test.exs @@ -675,13 +675,33 @@ defmodule LinkifyTest do assert Linkify.link(text) == expected end - test "Does not link trailing punctuation" do + test "Do not link trailing punctuation" do text = "You can find more info at https://pleroma.social." expected = "You can find more info at <a href=\"https://pleroma.social\">https://pleroma.social</a>." assert Linkify.link(text) == expected + + text = "Of course it was google.com!!" + + expected = "Of course it was <a href=\"http://google.com\">google.com</a>!!" + + assert Linkify.link(text) == expected + + text = + "First I had to login to hotmail.com, then I had to delete emails because my 15MB quota was full." + + expected = + "First I had to login to <a href=\"http://hotmail.com\">hotmail.com</a>, then I had to delete emails because my 15MB quota was full." + + assert Linkify.link(text) == expected + + text = "I looked at theonion.com; it was no longer funny." + + expected = "I looked at <a href=\"http://theonion.com\">theonion.com</a>; it was no longer funny." + + assert Linkify.link(text) == expected end test "IDN and punycode domain" do @@ -693,7 +713,8 @@ defmodule LinkifyTest do text = "xn--fraubcher-u9a.com says Neiiighhh!" - expected = "<a href=\"http://xn--fraubcher-u9a.com\">xn--fraubcher-u9a.com</a> says Neiiighhh!" + expected = + "<a href=\"http://xn--fraubcher-u9a.com\">xn--fraubcher-u9a.com</a> says Neiiighhh!" assert Linkify.link(text) == expected end