From 3999a61535e7472abe08c65ca0a91ed53767164d Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 13 Feb 2021 12:47:44 -0600 Subject: [PATCH 1/3] Correct test for apostrophes on mentions. It wasn't validating anything. --- test/linkify_test.exs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/linkify_test.exs b/test/linkify_test.exs index 64489c1..43c60ac 100644 --- a/test/linkify_test.exs +++ b/test/linkify_test.exs @@ -383,10 +383,17 @@ defmodule LinkifyTest do new_window: true ) == expected + expected = + "That's @user@example.com's server" + text = "That's @user@example.com's server" - assert Linkify.link(text, mention: true, mention_prefix: "https://example.com/user/") == - text + assert Linkify.link(text, + mention: true, + mention_prefix: "https://example.com/user/", + new_window: true + ) == + expected end test "mentions with no word-separation before them" do From de243909aab8a8ceedede9ae794361d1eb41a02d Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 13 Feb 2021 13:07:19 -0600 Subject: [PATCH 2/3] Try to strip common English apostrope contractions/abbreviations on words --- lib/linkify/parser.ex | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/linkify/parser.ex b/lib/linkify/parser.ex index 325b69c..3038b0e 100644 --- a/lib/linkify/parser.ex +++ b/lib/linkify/parser.ex @@ -17,6 +17,13 @@ defmodule Linkify.Parser do @delimiters ~r/[,.;:>?!]*$/ + @en_apostrophes [ + "'", + "'s", + "'ll", + "'d" + ] + @prefix_extra [ "magnet:?", "dweb://", @@ -209,6 +216,12 @@ defmodule Linkify.Parser do defp strip_punctuation(buffer), do: String.replace(buffer, @delimiters, "") + defp strip_en_apostrophes(buffer) do + Enum.reduce(@en_apostrophes, buffer, fn abbrev, buf -> + String.replace_suffix(buf, abbrev, "") + end) + end + def url?(buffer, opts) do valid_url?(buffer) && Regex.match?(@match_url, buffer) && valid_tld?(buffer, opts) end @@ -367,6 +380,7 @@ defmodule Linkify.Parser do buffer |> String.split("<") |> List.first() + |> strip_en_apostrophes() |> strip_punctuation() |> strip_parens() From dac0a32214042dfa1770116b5b67a6e9f56fa848 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 13 Feb 2021 13:08:48 -0600 Subject: [PATCH 3/3] Document improvements on linking mentions with apostrophes --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 095ed6e..476595c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed - Incorrect detection of IPv4 addresses causing random numbers (e.g., $123.45) to get linked +- Inability to link mentions with a trailing apostrophe. e.g., @user@example's ## 0.4.0 - 2020-11-24