From d83dbd9070e8af0ec6c36c1bbd11c417510fa7e3 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 5 Feb 2019 20:50:57 +0000 Subject: [PATCH] rich media: parser: reject any data which cannot be explicitly encoded into JSON --- lib/pleroma/web/rich_media/parser.ex | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index 32dec9887..38f1cdeec 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -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) -- 2.45.2