Fix linking problem.
authorlain <lain@soykaf.club>
Sat, 19 May 2018 09:27:14 +0000 (11:27 +0200)
committerlain <lain@soykaf.club>
Sat, 19 May 2018 09:27:14 +0000 (11:27 +0200)
lib/pleroma/formatter.ex
test/formatter_test.exs

index 456416fbdff4eecc6127ee9ea36bbd486cc6ecd7..395a0ac556dfc0eeb019659990517782292f6b25 100644 (file)
@@ -160,6 +160,7 @@ defmodule Pleroma.Formatter 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
index 2cf1f3f8e7cf2685bd9585be4637034b41c17d9a..e89b36663ce6da79974e243a9c0a2f64fac826e4 100644 (file)
@@ -78,6 +78,13 @@ defmodule Pleroma.FormatterTest do
         "<a href=\"https://en.wikipedia.org/wiki/Duff&#39;s_device\">https://en.wikipedia.org/wiki/Duff&#39;s_device</a>"
 
       assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
+
+      text = "https://pleroma.com https://pleroma.com/sucks"
+
+      expected =
+        "<a href=\"https://pleroma.com\">https://pleroma.com</a> <a href=\"https://pleroma.com/sucks\">https://pleroma.com/sucks</a>"
+
+      assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
     end
   end