Merge branch 'fix-test' into 'develop'
authorlambda <pleromagit@rogerbraun.net>
Mon, 17 Dec 2018 20:24:58 +0000 (20:24 +0000)
committerlambda <pleromagit@rogerbraun.net>
Mon, 17 Dec 2018 20:24:58 +0000 (20:24 +0000)
Fix uploads test.

See merge request pleroma/pleroma!564

lib/pleroma/web/twitter_api/views/activity_view.ex
lib/pleroma/web/twitter_api/views/user_view.ex
test/web/twitter_api/views/activity_view_test.exs

index 0699bf1da9f0d0b737cff5720e65c134746b4265..91d0867408d3c75fc4ca1755777a93e3a26c9e7d 100644 (file)
@@ -244,6 +244,11 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
       |> HTML.filter_tags(User.html_filter_policy(opts[:for]))
       |> Formatter.emojify(object["emoji"])
 
+    text =
+      content
+      |> String.replace(~r/<br\s?\/?>/, "\n")
+      |> HTML.strip_tags()
+
     reply_parent = Activity.get_in_reply_to_activity(activity)
 
     reply_user = reply_parent && User.get_cached_by_ap_id(reply_parent.actor)
@@ -253,7 +258,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
       "uri" => activity.data["object"]["id"],
       "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
       "statusnet_html" => html,
-      "text" => HTML.strip_tags(content),
+      "text" => text,
       "is_local" => activity.local,
       "is_post_verb" => true,
       "created_at" => created_at,
index b3459af9af7768cc2316b1f122f75fecfeee193f..8a88d72b1bf07ed2d006bc1d7730b7566c66a4c0 100644 (file)
@@ -86,7 +86,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
     }
 
     if assigns[:token] do
-      Map.put(data, "token", assigns[:token])
+      Map.put(data, "token", token_string(assigns[:token]))
     else
       data
     end
@@ -111,4 +111,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
 
   defp image_url(%{"url" => [%{"href" => href} | _]}), do: href
   defp image_url(_), do: nil
+
+  defp token_string(%Pleroma.Web.OAuth.Token{token: token_str}), do: token_str
+  defp token_string(token), do: token
 end
index 77b8d99e798d03e8d378b041a81dd25b6fcb77b5..8aa9e3130dc4aaba2be6a972a6c6616442fa3bd6 100644 (file)
@@ -14,6 +14,22 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
   import Pleroma.Factory
   import Mock
 
+  test "a create activity with a html status" do
+    text = """
+    #Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg
+    """
+
+    {:ok, activity} = CommonAPI.post(insert(:user), %{"status" => text})
+
+    result = ActivityView.render("activity.json", activity: activity)
+
+    assert result["statusnet_html"] ==
+             "<a data-tag=\"bike\" href=\"http://localhost:4001/tag/bike\">#Bike</a> log - Commute Tuesday<br /><a href=\"https://pla.bike/posts/20181211/\">https://pla.bike/posts/20181211/</a><br /><a data-tag=\"cycling\" href=\"http://localhost:4001/tag/cycling\">#cycling</a> <a data-tag=\"chscycling\" href=\"http://localhost:4001/tag/chscycling\">#CHScycling</a> <a data-tag=\"commute\" href=\"http://localhost:4001/tag/commute\">#commute</a><br />MVIMG_20181211_054020.jpg"
+
+    assert result["text"] ==
+             "#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg"
+  end
+
   test "a create activity with a note" do
     user = insert(:user)
     other_user = insert(:user, %{nickname: "shp"})