From b87be206a72dc77787037b18b11c86200c6f2cc1 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 18 Nov 2020 17:24:44 +0000 Subject: [PATCH 1/3] Support URLs with FQDNs (trailing period on the tld) --- lib/linkify/parser.ex | 2 +- test/linkify_test.exs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/linkify/parser.ex b/lib/linkify/parser.ex index 64d08db..d329e37 100644 --- 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 index 73ff6d0..f7bfc68 100644 --- a/test/linkify_test.exs +++ b/test/linkify_test.exs @@ -657,5 +657,15 @@ 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: https://www.wired.com./story/marissa-mayer-startup-sunshine-contacts/" + + assert Linkify.link(text) == expected + end end end From 1f8680f4b451f23835bf3fd0d4b0d307fede6de3 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 18 Nov 2020 17:26:17 +0000 Subject: [PATCH 2/3] Document FQDN support --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bc73be..256bea6 100644 --- 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 From 372879c8d4dd402ffe82994184a9283695430141 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 18 Nov 2020 17:40:10 +0000 Subject: [PATCH 3/3] Verify trailing periods as sentence punctuation do not link --- test/linkify_test.exs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/linkify_test.exs b/test/linkify_test.exs index f7bfc68..2568052 100644 --- a/test/linkify_test.exs +++ b/test/linkify_test.exs @@ -667,5 +667,14 @@ defmodule LinkifyTest do 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 https://pleroma.social." + + assert Linkify.link(text) == expected + end end end