From 0787f0dfbe8daad53617217617fbc8784e45898f Mon Sep 17 00:00:00 2001 From: scarlett Date: Sat, 5 Jan 2019 17:28:47 +0000 Subject: [PATCH 1/5] Strip HTML in and allow emoji in summaries. --- lib/pleroma/web/common_api/common_api.ex | 2 +- lib/pleroma/web/twitter_api/views/activity_view.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index e474653ff..a20b854df 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -124,7 +124,7 @@ def post(user, %{"status" => status} = data) do Map.put( object, "emoji", - Formatter.get_emoji(status) + Formatter.get_emoji(status) ++ Formatter.get_emoji(data["spoiler_text"]) |> Enum.reduce(%{}, fn {name, file}, acc -> Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url()}#{file}") end) diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 84f35ebf9..9ba347d12 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -285,7 +285,7 @@ def render( "activity_type" => "post", "possibly_sensitive" => possibly_sensitive, "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object), - "summary" => summary + "summary" => HTML.strip_tags(summary) |> Formatter.emojify(object["emoji"]) } end From 3c86d907d4d298b8a54d5292ff85107a1ada3bd5 Mon Sep 17 00:00:00 2001 From: scarlett Date: Sat, 5 Jan 2019 17:35:39 +0000 Subject: [PATCH 2/5] add some brakets to the emoji list. --- lib/pleroma/web/common_api/common_api.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index a20b854df..bb3c38f00 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -124,7 +124,7 @@ def post(user, %{"status" => status} = data) do Map.put( object, "emoji", - Formatter.get_emoji(status) ++ Formatter.get_emoji(data["spoiler_text"]) + (Formatter.get_emoji(status) ++ Formatter.get_emoji(data["spoiler_text"])) |> Enum.reduce(%{}, fn {name, file}, acc -> Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url()}#{file}") end) From 6556be344de981272b9c14faf5fb9837c1ea0da6 Mon Sep 17 00:00:00 2001 From: scarlett Date: Sat, 5 Jan 2019 18:20:42 +0000 Subject: [PATCH 3/5] Resolve some test failures. --- .../web/twitter_api/representers/activity_representer.ex | 2 +- test/web/twitter_api/views/activity_view_test.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 2a221cc66..245cd52fd 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -207,7 +207,7 @@ def to_map( "activity_type" => "post", "possibly_sensitive" => possibly_sensitive, "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object), - "summary" => object["summary"] + "summary" => HTML.strip_tags(object["summary"]) |> Formatter.emojify(object["emoji"]) } end diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 013245033..40c4abc39 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -73,6 +73,7 @@ test "a create activity with a note" do "repeat_num" => 0, "repeated" => false, "statusnet_conversation_id" => convo_id, + "summary" => "", "statusnet_html" => "Hey @shp!", "tags" => [], @@ -80,7 +81,6 @@ test "a create activity with a note" do "uri" => activity.data["object"]["id"], "user" => UserView.render("show.json", %{user: user}), "visibility" => "direct", - "summary" => nil } assert result == expected From 096e121879f5e9aad694f1b57438f0545ecd73b3 Mon Sep 17 00:00:00 2001 From: scarlett Date: Sat, 5 Jan 2019 18:25:36 +0000 Subject: [PATCH 4/5] Remove redundant comma. --- test/web/twitter_api/views/activity_view_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 40c4abc39..32a08dbc9 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -80,7 +80,7 @@ test "a create activity with a note" do "text" => "Hey @shp!", "uri" => activity.data["object"]["id"], "user" => UserView.render("show.json", %{user: user}), - "visibility" => "direct", + "visibility" => "direct" } assert result == expected From 57df7d6e1da1a94a3866afc9b6d353aea602d4d3 Mon Sep 17 00:00:00 2001 From: scarlett Date: Sat, 5 Jan 2019 21:46:42 +0000 Subject: [PATCH 5/5] Add tests for emoji and lack of HTML in summaries. --- .../twitter_api/views/activity_view_test.exs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 32a08dbc9..05780a54a 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -41,6 +41,35 @@ test "a create activity with a html status" do "#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg" end + test "a create activity with a summary containing emoji" do + {:ok, activity} = + CommonAPI.post(insert(:user), %{ + "spoiler_text" => ":woollysocks: meow", + "status" => "." + }) + + result = ActivityView.render("activity.json", activity: activity) + + expected = + "\"woollysocks\" meow" + + assert result["summary"] == expected + end + + test "a create activity with a summary containing invalid HTML" do + {:ok, activity} = + CommonAPI.post(insert(:user), %{ + "spoiler_text" => "meow", + "status" => "." + }) + + result = ActivityView.render("activity.json", activity: activity) + + expected = "meow" + + assert result["summary"] == expected + end + test "a create activity with a note" do user = insert(:user) other_user = insert(:user, %{nickname: "shp"})