Do not truncate DM when it contains newlines and safe_dm_mentions is set to true
authorSergey Suprunenko <suprunenko.s@gmail.com>
Wed, 22 May 2019 04:04:20 +0000 (04:04 +0000)
committerkaniini <nenolod@gmail.com>
Wed, 22 May 2019 04:04:20 +0000 (04:04 +0000)
lib/pleroma/formatter.ex
test/formatter_test.exs

index 3d7c36d215a6c5603fb4e8ac32a98f9187424014..3e3b9fe9757f3e4e037bbd722e41a97695088daf 100644 (file)
@@ -8,7 +8,7 @@ defmodule Pleroma.Formatter do
   alias Pleroma.User
   alias Pleroma.Web.MediaProxy
 
-  @safe_mention_regex ~r/^(\s*(?<mentions>@.+?\s+)+)(?<rest>.*)/
+  @safe_mention_regex ~r/^(\s*(?<mentions>@.+?\s+)+)(?<rest>.*)/s
   @link_regex ~r"((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+"ui
   @markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/
 
index 5e70111605f3f738152d662035153bc0d39264c1..47b91b121fe944528f2a71b9fc569c353ea07885 100644 (file)
@@ -206,6 +206,15 @@ defmodule Pleroma.FormatterTest do
       assert mentions == []
       assert expected_text == text
     end
+
+    test "given the 'safe_mention' option, it will keep text after newlines" do
+      user = insert(:user)
+      text = " @#{user.nickname}\n hey dude\n\nhow are you doing?"
+
+      {expected_text, _, _} = Formatter.linkify(text, safe_mention: true)
+
+      assert expected_text =~ "how are you doing?"
+    end
   end
 
   describe ".parse_tags" do