add scrubber for html special char
authorSachin Joshi <satchin.joshi@gmail.com>
Tue, 30 Apr 2019 19:52:17 +0000 (01:37 +0545)
committerSachin Joshi <satchin.joshi@gmail.com>
Tue, 30 Apr 2019 19:52:17 +0000 (01:37 +0545)
lib/pleroma/html.ex
lib/pleroma/web/twitter_api/views/activity_view.ex

index cf6c0ee0a9535f0d57dedacaa72916ee8680f218..eb33d12d9e88d87f25ddeae0352a0c1851f72d38 100644 (file)
@@ -28,12 +28,18 @@ defmodule Pleroma.HTML do
   def filter_tags(html), do: filter_tags(html, nil)
   def strip_tags(html), do: Scrubber.scrub(html, Scrubber.StripTags)
 
-  def get_cached_scrubbed_html_for_activity(content, scrubbers, activity, key \\ "") do
+  def get_cached_scrubbed_html_for_activity(
+        content,
+        scrubbers,
+        activity,
+        key \\ "",
+        callback \\ fn x -> x end
+      ) do
     key = "#{key}#{generate_scrubber_signature(scrubbers)}|#{activity.id}"
 
     Cachex.fetch!(:scrubber_cache, key, fn _key ->
       object = Pleroma.Object.normalize(activity)
-      ensure_scrubbed_html(content, scrubbers, object.data["fake"] || false)
+      ensure_scrubbed_html(content, scrubbers, object.data["fake"] || false, callback)
     end)
   end
 
@@ -42,16 +48,27 @@ defmodule Pleroma.HTML do
       content,
       HtmlSanitizeEx.Scrubber.StripTags,
       activity,
-      key
+      key,
+      &HtmlEntities.decode/1
     )
   end
 
   def ensure_scrubbed_html(
         content,
         scrubbers,
-        false = _fake
+        fake,
+        callback
       ) do
-    {:commit, filter_tags(content, scrubbers)}
+    content =
+      content
+      |> filter_tags(scrubbers)
+      |> callback.()
+
+    if fake do
+      {:ignore, content}
+    else
+      {:commit, content}
+    end
   end
 
   def ensure_scrubbed_html(
index 1007a2a48de577a19cf5ed7957da7a4ce19d68ef..c64152da8f844cde4f5e70dfdee7fba3bb7af7bf 100644 (file)
@@ -289,7 +289,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
       "uri" => object.data["id"],
       "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
       "statusnet_html" => html,
-      "text" => HtmlEntities.decode(text),
+      "text" => text,
       "is_local" => activity.local,
       "is_post_verb" => true,
       "created_at" => created_at,