forked from AkkomaGang/akkoma
rich media: parser: reject any data which cannot be explicitly encoded into JSON
This commit is contained in:
parent
d120aa63f0
commit
d83dbd9070
1 changed files with 4 additions and 14 deletions
|
@ -54,22 +54,12 @@ defp check_parsed_data(data) do
|
||||||
{:error, "Found metadata was invalid or incomplete: #{inspect(data)}"}
|
{:error, "Found metadata was invalid or incomplete: #{inspect(data)}"}
|
||||||
end
|
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
|
defp clean_parsed_data(data) do
|
||||||
data
|
data
|
||||||
|> Enum.reject(fn {_, val} ->
|
|> Enum.reject(fn {key, val} ->
|
||||||
case string_is_valid_unicode(val) do
|
with {:ok, _} <- Jason.encode(%{key => val}) do
|
||||||
{:ok, _} -> false
|
false
|
||||||
|
else
|
||||||
_ -> true
|
_ -> true
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in a new issue