Browse Source

Merge branch 'bugfix/rich-media-non-unicode-nuclear-option' into 'develop'

rich media: parser: reject any data which cannot be explicitly encoded into JSON

Closes #596

See merge request pleroma/pleroma!779
tags/v0.9.9
rinpatch 5 years ago
parent
commit
c46490b199
1 changed files with 4 additions and 14 deletions
  1. +4
    -14
      lib/pleroma/web/rich_media/parser.ex

+ 4
- 14
lib/pleroma/web/rich_media/parser.ex View 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)


Loading…
Cancel
Save