Fix the issue with HTML scrubber
authorrinpatch <rinpatch@sdf.org>
Mon, 1 Apr 2019 08:55:59 +0000 (11:55 +0300)
committerrinpatch <rinpatch@sdf.org>
Mon, 1 Apr 2019 08:55:59 +0000 (11:55 +0300)
lib/pleroma/html.ex
lib/pleroma/object.ex
lib/pleroma/web/activity_pub/activity_pub.ex

index 5b152d926ed57d66b4d4acde5248955f6891d4dc..f19b42b42c470250f9be48b3b13358b7d74a4f33 100644 (file)
@@ -28,9 +28,13 @@ defmodule Pleroma.HTML do
   def filter_tags(html), do: filter_tags(html, nil)
   def strip_tags(html), do: Scrubber.scrub(html, Scrubber.StripTags)
 
+  # TODO: rename object to activity because that's what it is really working with
   def get_cached_scrubbed_html_for_object(content, scrubbers, object, module) do
     key = "#{module}#{generate_scrubber_signature(scrubbers)}|#{object.id}"
-    Cachex.fetch!(:scrubber_cache, key, fn _key -> ensure_scrubbed_html(content, scrubbers) end)
+
+    Cachex.fetch!(:scrubber_cache, key, fn _key ->
+      ensure_scrubbed_html(content, scrubbers, object.data["object"]["fake"] || false)
+    end)
   end
 
   def get_cached_stripped_html_for_object(content, object, module) do
@@ -44,11 +48,20 @@ defmodule Pleroma.HTML do
 
   def ensure_scrubbed_html(
         content,
-        scrubbers
+        scrubbers,
+        _fake = false
       ) do
     {:commit, filter_tags(content, scrubbers)}
   end
 
+  def ensure_scrubbed_html(
+        content,
+        scrubbers,
+        _fake = true
+      ) do
+    {:ignore, filter_tags(content, scrubbers)}
+  end
+
   defp generate_scrubber_signature(scrubber) when is_atom(scrubber) do
     generate_scrubber_signature([scrubber])
   end
index 8a670645d424aa3b9ef0688935b2101ec92527e8..013d6215710ec42858ab18ed3be69e6775e405ed 100644 (file)
@@ -44,6 +44,11 @@ defmodule Pleroma.Object do
   # Use this whenever possible, especially when walking graphs in an O(N) loop!
   def normalize(%Activity{object: %Object{} = object}), do: object
 
+  # A hack for fake activities
+  def normalize(%Activity{data: %{"object" => %{"fake" => true} = data}}) do
+    %Object{id: "pleroma:fake_object_id", data: data}
+  end
+
   # Catch and log Object.normalize() calls where the Activity's child object is not
   # preloaded.
   def normalize(%Activity{data: %{"object" => %{"id" => ap_id}}}) do
index a94040d01a3384977d83c69b824f1f77897e63ca..716a40419b6679dd4f53ddbfcbb27756efc6d202 100644 (file)
@@ -150,14 +150,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
         {:ok, activity}
 
       {:fake, true, map, recipients} ->
-        {:ok,
-         %Activity{
-           data: map,
-           local: local,
-           actor: map["actor"],
-           recipients: recipients,
-           id: "pleroma:fakeid"
-         }}
+        map =
+          map
+          |> put_in(["object", "fake"], true)
+
+        activity = %Activity{
+          data: map,
+          local: local,
+          actor: map["actor"],
+          recipients: recipients,
+          id: "pleroma:fakeid"
+        }
+
+        # Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+        {:ok, activity}
 
       error ->
         {:error, error}