Make normalize_markup multilang aware
This commit is contained in:
parent
e958ec57db
commit
fb2688952f
2 changed files with 39 additions and 4 deletions
|
@ -16,11 +16,27 @@ def filter(%{"type" => type, "object" => child_object} = object)
|
||||||
when type in ["Create", "Update"] do
|
when type in ["Create", "Update"] do
|
||||||
scrub_policy = Pleroma.Config.get([:mrf_normalize_markup, :scrub_policy])
|
scrub_policy = Pleroma.Config.get([:mrf_normalize_markup, :scrub_policy])
|
||||||
|
|
||||||
content =
|
object =
|
||||||
child_object["content"]
|
with %{} = content_map <- child_object["contentMap"] do
|
||||||
|> HTML.filter_tags(scrub_policy)
|
fixed_content_map =
|
||||||
|
Enum.reduce(content_map, %{}, fn {lang, content}, acc ->
|
||||||
|
Map.put(acc, lang, HTML.filter_tags(content, scrub_policy))
|
||||||
|
end)
|
||||||
|
|
||||||
object = put_in(object, ["object", "content"], content)
|
object
|
||||||
|
|> put_in(["object", "contentMap"], fixed_content_map)
|
||||||
|
|> put_in(
|
||||||
|
["object", "content"],
|
||||||
|
Pleroma.MultiLanguage.map_to_str(fixed_content_map, multiline: true)
|
||||||
|
)
|
||||||
|
else
|
||||||
|
_ ->
|
||||||
|
content =
|
||||||
|
child_object["content"]
|
||||||
|
|> HTML.filter_tags(scrub_policy)
|
||||||
|
|
||||||
|
put_in(object, ["object", "content"], content)
|
||||||
|
end
|
||||||
|
|
||||||
{:ok, object}
|
{:ok, object}
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,6 +38,25 @@ test "it filter html tags" do
|
||||||
assert res["object"]["content"] == @expected
|
assert res["object"]["content"] == @expected
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "multilang-aware" do
|
||||||
|
message = %{
|
||||||
|
"type" => "Create",
|
||||||
|
"object" => %{
|
||||||
|
"content" => "some",
|
||||||
|
"contentMap" => %{
|
||||||
|
"a" => @html_sample,
|
||||||
|
"b" => @html_sample
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {:ok, res} = NormalizeMarkup.filter(message)
|
||||||
|
assert res["object"]["contentMap"] == %{"a" => @expected, "b" => @expected}
|
||||||
|
|
||||||
|
assert res["object"]["content"] ==
|
||||||
|
Pleroma.MultiLanguage.map_to_str(res["object"]["contentMap"], multiline: true)
|
||||||
|
end
|
||||||
|
|
||||||
test "history-aware" do
|
test "history-aware" do
|
||||||
message = %{
|
message = %{
|
||||||
"type" => "Create",
|
"type" => "Create",
|
||||||
|
|
Loading…
Reference in a new issue