From df95118c819ae15f0de43519f2f9f9753ac60ec2 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 19 May 2018 11:27:14 +0200 Subject: [PATCH] Fix linking problem. --- lib/pleroma/formatter.ex | 1 + test/formatter_test.exs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 456416fbd..395a0ac55 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -160,6 +160,7 @@ def add_links({subs, text}) do links = Regex.scan(@link_regex, text) |> Enum.map(fn [url] -> {Ecto.UUID.generate(), url} end) + |> Enum.sort_by(fn ({_, url}) -> -String.length(url) end) uuid_text = links diff --git a/test/formatter_test.exs b/test/formatter_test.exs index 2cf1f3f8e..e89b36663 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -78,6 +78,13 @@ test "turning urls into links" do "https://en.wikipedia.org/wiki/Duff's_device" assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected + + text = "https://pleroma.com https://pleroma.com/sucks" + + expected = + "https://pleroma.com https://pleroma.com/sucks" + + assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected end end