From 3ccfe226c0e7710c2321b19643a43fcc6458a1e9 Mon Sep 17 00:00:00 2001 From: Vald Date: Thu, 6 Dec 2018 01:05:41 +0530 Subject: [PATCH 1/7] added data attrs for user and tag --- lib/pleroma/formatter.ex | 10 +++++++--- lib/pleroma/html.ex | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 1a5c07c8a..5b03e9aeb 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -114,7 +114,7 @@ def add_user_links({subs, text}, mentions) do subs = subs ++ - Enum.map(mentions, fn {match, %User{ap_id: ap_id, info: info}, uuid} -> + Enum.map(mentions, fn {match, %User{id: id, ap_id: ap_id, info: info}, uuid} -> ap_id = if is_binary(info.source_data["url"]) do info.source_data["url"] @@ -125,7 +125,7 @@ def add_user_links({subs, text}, mentions) do short_match = String.split(match, "@") |> tl() |> hd() {uuid, - "@#{short_match}"} + "@#{short_match}"} end) {subs, uuid_text} @@ -147,7 +147,11 @@ def add_hashtag_links({subs, text}, tags) do subs = subs ++ Enum.map(tags, fn {tag_text, tag, uuid} -> - url = "" + url = + "" + {uuid, url} end) diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 1b920d7fd..271a48b57 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -86,7 +86,7 @@ defmodule Pleroma.HTML.Scrubber.Default do Meta.remove_cdata_sections_before_scrub() Meta.strip_comments() - Meta.allow_tag_with_uri_attributes("a", ["href"], @valid_schemes) + Meta.allow_tag_with_uri_attributes("a", ["href", "data-user", "data-tag"], @valid_schemes) Meta.allow_tag_with_these_attributes("a", ["name", "title"]) Meta.allow_tag_with_these_attributes("abbr", ["title"]) From 812b20d49f1ef31cf1582e17c74ef68cacd8d912 Mon Sep 17 00:00:00 2001 From: Vald Date: Thu, 6 Dec 2018 01:27:08 +0530 Subject: [PATCH 2/7] resolved formatter_test failures --- test/formatter_test.exs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/formatter_test.exs b/test/formatter_test.exs index 5d745510f..84d826295 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -15,7 +15,7 @@ test "turns hashtags into links" do text = "I love #cofe and #2hu" expected_text = - "I love and " + "I love and " tags = Formatter.parse_tags(text) @@ -128,9 +128,9 @@ test "gives a replacement for user links" do Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end) expected_text = - "@gsimg According to @gsimg According to @archaeme, that is @daggsy. Also hello @archaeme, that is @daggsy. Also hello @archaeme" @@ -150,7 +150,7 @@ test "gives a replacement for user links when the user is using Osada" do Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end) expected_text = - "@mike test" + "@mike test" assert expected_text == Formatter.finalize({subs, text}) end @@ -166,7 +166,7 @@ test "gives a replacement for single-character local nicknames" do assert length(subs) == 1 Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end) - expected_text = "@o hi" + expected_text = "@o hi" assert expected_text == Formatter.finalize({subs, text}) end From 743a09132bb6f9d3ecd6404e4a20e6a08598d8a7 Mon Sep 17 00:00:00 2001 From: Vald Date: Thu, 6 Dec 2018 01:28:52 +0530 Subject: [PATCH 3/7] linting --- test/formatter_test.exs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/formatter_test.exs b/test/formatter_test.exs index 84d826295..abb9d882c 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -128,11 +128,11 @@ test "gives a replacement for user links" do Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end) expected_text = - "@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme" + "@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme" assert expected_text == Formatter.finalize({subs, text}) end @@ -166,7 +166,9 @@ test "gives a replacement for single-character local nicknames" do assert length(subs) == 1 Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end) - expected_text = "@o hi" + expected_text = + "@o hi" + assert expected_text == Formatter.finalize({subs, text}) end From 911a877576f1f2036fe2c7a7f22cf634ca3e5234 Mon Sep 17 00:00:00 2001 From: Vald Date: Thu, 6 Dec 2018 01:46:30 +0530 Subject: [PATCH 4/7] resolved api and controller test failures --- test/web/mastodon_api/mastodon_api_controller_test.exs | 6 +++--- test/web/twitter_api/twitter_api_controller_test.exs | 2 +- test/web/twitter_api/twitter_api_test.exs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 7cd98cde8..eb483afdf 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -590,7 +590,7 @@ test "list of notifications", %{conn: conn} do |> get("/api/v1/notifications") expected_response = - "hi @#{user.nickname}" + "hi @#{user.nickname}" assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200) assert response == expected_response @@ -611,7 +611,7 @@ test "getting a single notification", %{conn: conn} do |> get("/api/v1/notifications/#{notification.id}") expected_response = - "hi @#{user.nickname}" + "hi @#{user.nickname}" assert %{"status" => %{"content" => response}} = json_response(conn, 200) assert response == expected_response @@ -1271,7 +1271,7 @@ test "updates the user's bio", %{conn: conn} do assert user = json_response(conn, 200) assert user["note"] == - "I drink #cofe with #cofe with @#{user2.nickname}" end diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index a6495ffc1..e799a0518 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -969,7 +969,7 @@ test "it updates a user's profile", %{conn: conn} do assert user.name == "new name" assert user.bio == - "hi @#{user2.nickname}" + "hi @#{user2.nickname}" assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user}) end diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 28230699f..76de68783 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -10,7 +10,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do test "create a status" do user = insert(:user) - _mentioned_user = insert(:user, %{nickname: "shp", ap_id: "shp"}) + mentioned_user = insert(:user, %{nickname: "shp", ap_id: "shp"}) object_data = %{ "type" => "Image", @@ -35,7 +35,7 @@ test "create a status" do {:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input) expected_text = - "Hello again, @shp.<script></script>
This is on another :moominmamma: line.
image.jpg" + "Hello again, @shp.<script></script>
This is on another :moominmamma: line.
image.jpg" assert get_in(activity.data, ["object", "content"]) == expected_text assert get_in(activity.data, ["object", "type"]) == "Note" @@ -281,7 +281,7 @@ test "it registers a new user and parses mentions in the bio" do {:ok, user2} = TwitterAPI.register_user(data2) expected_text = - "@john test" + "@john test" assert user2.bio == expected_text end From 028904c33321a17f0f04c1a43dcf3eaeeeb80c1c Mon Sep 17 00:00:00 2001 From: Vald Date: Thu, 6 Dec 2018 01:46:53 +0530 Subject: [PATCH 5/7] lint --- test/web/mastodon_api/mastodon_api_controller_test.exs | 6 +++--- test/web/twitter_api/twitter_api_controller_test.exs | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index eb483afdf..b5da2044a 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -1271,9 +1271,9 @@ test "updates the user's bio", %{conn: conn} do assert user = json_response(conn, 200) assert user["note"] == - "I drink #cofe with @#{user2.nickname}" + "I drink #cofe with @#{user2.nickname}" end test "updates the user's locking status", %{conn: conn} do diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index e799a0518..77a89ba06 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -969,7 +969,9 @@ test "it updates a user's profile", %{conn: conn} do assert user.name == "new name" assert user.bio == - "hi @#{user2.nickname}" + "hi @#{ + user2.nickname + }" assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user}) end From 3c8ffe7ed326f4c0bc515f35c905b405e90391b0 Mon Sep 17 00:00:00 2001 From: Vald Date: Thu, 6 Dec 2018 01:54:04 +0530 Subject: [PATCH 6/7] resolved activity view test --- 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 5cef06f88..bc36b0e90 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -47,7 +47,7 @@ test "a create activity with a note" do "repeated" => false, "statusnet_conversation_id" => convo_id, "statusnet_html" => - "Hey @shp!", + "Hey @shp!", "tags" => [], "text" => "Hey @shp!", "uri" => activity.data["object"]["id"], From 194869c7db1d31b139254d3a0c6a449cee0068fe Mon Sep 17 00:00:00 2001 From: Vald Date: Thu, 6 Dec 2018 02:14:56 +0530 Subject: [PATCH 7/7] added data attrs to twitter scrubber --- lib/pleroma/html.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 271a48b57..5daaa5e69 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -45,7 +45,7 @@ defmodule Pleroma.HTML.Scrubber.TwitterText do Meta.strip_comments() # links - Meta.allow_tag_with_uri_attributes("a", ["href"], @valid_schemes) + Meta.allow_tag_with_uri_attributes("a", ["href", "data-user", "data-tag"], @valid_schemes) Meta.allow_tag_with_these_attributes("a", ["name", "title"]) # paragraphs and linebreaks