logo

auto_linker

AutoLinker-shim, based on https://git.pleroma.social/pleroma/auto_linker
commit: b50bd58d707ccaae782b8118a38e3c4f165c3886
parent 815343e824f0853ec0bb8d91419e7d8f175fa820
Author: feld <feld@feld.me>
Date:   Wed, 18 Nov 2020 17:47:54 +0000

Merge branch 'fix/fqdn-domain' into 'master'

Support linking URLs with FQDNs

See merge request pleroma/elixir-libraries/linkify!30

Diffstat:

MCHANGELOG.md4++++
Mlib/linkify/parser.ex2+-
Mtest/linkify_test.exs19+++++++++++++++++++
3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Added + +- Support for linking URLs with FQDNs (e.g., "google.com.") + ## 0.3.0 - 2020-11-17 ### Added diff --git a/lib/linkify/parser.ex b/lib/linkify/parser.ex @@ -247,7 +247,7 @@ defmodule Linkify.Parser do true true -> - tld = host |> String.split(".") |> List.last() + tld = host |> String.trim_trailing(".") |> String.split(".") |> List.last() MapSet.member?(@tlds, tld) end end diff --git a/test/linkify_test.exs b/test/linkify_test.exs @@ -657,5 +657,24 @@ defmodule LinkifyTest do assert Linkify.link(text) == expected end + + test "FQDN (with trailing period)" do + text = + "Check out this article: https://www.wired.com./story/marissa-mayer-startup-sunshine-contacts/" + + expected = + "Check out this article: <a href=\"https://www.wired.com./story/marissa-mayer-startup-sunshine-contacts/\">https://www.wired.com./story/marissa-mayer-startup-sunshine-contacts/</a>" + + assert Linkify.link(text) == expected + end + + test "Does 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 + end end end