Linkify fixes.
authorRoger Braun <rbraun@Bobble.local>
Tue, 7 Nov 2017 11:06:37 +0000 (12:06 +0100)
committerRoger Braun <rbraun@Bobble.local>
Tue, 7 Nov 2017 11:06:37 +0000 (12:06 +0100)
lib/pleroma/formatter.ex
test/formatter_test.exs

index f062d9a5896b6e928e8f253c86c1978d0e2c0c57..7ccd7e7bb8bdcad4dbfa7ab2020ef670e3f43949 100644 (file)
@@ -1,7 +1,7 @@
 defmodule Pleroma.Formatter do
   alias Pleroma.User
 
-  @link_regex ~r/https?:\/\/[\w\.\/?=\-#%&]+[\w]/u
+  @link_regex ~r/https?:\/\/[\w\.\/?=\-#%&@~]+[\w\/]/u
   def linkify(text) do
     Regex.replace(@link_regex, text, "<a href='\\0'>\\0</a>")
   end
index d96f433f93f4f1880c74abd468a628fb80ab9767..f919738812c696c3b357880cd631cf1e2888364f 100644 (file)
@@ -7,10 +7,24 @@ defmodule Pleroma.FormatterTest do
   describe ".linkify" do
     test "turning urls into links" do
       text = "Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla."
-
       expected = "Hey, check out <a href='https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla'>https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla</a>."
 
       assert Formatter.linkify(text) == expected
+
+      text = "https://mastodon.social/@lambadalambda"
+      expected = "<a href='https://mastodon.social/@lambadalambda'>https://mastodon.social/@lambadalambda</a>"
+
+      assert Formatter.linkify(text) == expected
+
+      text = "@lambadalambda"
+      expected = "@lambadalambda"
+
+      assert Formatter.linkify(text) == expected
+
+      text = "http://www.cs.vu.nl/~ast/intel/"
+      expected = "<a href='http://www.cs.vu.nl/~ast/intel/'>http://www.cs.vu.nl/~ast/intel/</a>"
+
+      assert Formatter.linkify(text) == expected
     end
   end