2020-04-28 14:26:19 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-04-28 14:26:19 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-06-16 14:50:33 +00:00
|
|
|
defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.SafeText do
|
2020-04-28 14:26:19 +00:00
|
|
|
use Ecto.Type
|
|
|
|
|
|
|
|
alias Pleroma.HTML
|
|
|
|
|
|
|
|
def type, do: :string
|
|
|
|
|
|
|
|
def cast(str) when is_binary(str) do
|
2020-05-30 10:17:18 +00:00
|
|
|
{:ok, HTML.filter_tags(str)}
|
2020-04-28 14:26:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def cast(_), do: :error
|
|
|
|
|
|
|
|
def dump(data) do
|
|
|
|
{:ok, data}
|
|
|
|
end
|
|
|
|
|
|
|
|
def load(data) do
|
|
|
|
{:ok, data}
|
|
|
|
end
|
|
|
|
end
|