rich media: parser: reject any data which cannot be explicitly encoded into JSON
authorWilliam Pitcock <nenolod@dereferenced.org>
Tue, 5 Feb 2019 20:50:57 +0000 (20:50 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Tue, 5 Feb 2019 20:50:57 +0000 (20:50 +0000)
lib/pleroma/web/rich_media/parser.ex

index 32dec98873e93b8df43525c5b4a951cd3f534520..38f1cdeecb5c83ded6d18ca0357cd92700d8d896 100644 (file)
@@ -54,22 +54,12 @@ defmodule Pleroma.Web.RichMedia.Parser do
     {:error, "Found metadata was invalid or incomplete: #{inspect(data)}"}
   end
 
-  defp string_is_valid_unicode(data) when is_binary(data) do
-    data
-    |> :unicode.characters_to_binary()
-    |> clean_string()
-  end
-
-  defp string_is_valid_unicode(data), do: {:ok, data}
-
-  defp clean_string({:error, _, _}), do: {:error, "Invalid data"}
-  defp clean_string(data), do: {:ok, data}
-
   defp clean_parsed_data(data) do
     data
-    |> Enum.reject(fn {_, val} ->
-      case string_is_valid_unicode(val) do
-        {:ok, _} -> false
+    |> Enum.reject(fn {key, val} ->
+      with {:ok, _} <- Jason.encode(%{key => val}) do
+        false
+      else
         _ -> true
       end
     end)