Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85949762
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/pleroma/ecto_type/activity_pub/object_validators/map_of_string.ex b/lib/pleroma/ecto_type/activity_pub/object_validators/map_of_string.ex
index 441c8c181..dc071cbfc 100644
--- a/lib/pleroma/ecto_type/activity_pub/object_validators/map_of_string.ex
+++ b/lib/pleroma/ecto_type/activity_pub/object_validators/map_of_string.ex
@@ -1,47 +1,47 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.MapOfString do
use Ecto.Type
def type, do: :map
def cast(object) when is_map(object) do
data =
object
|> Enum.reduce(%{}, fn
{lang, value}, acc when is_binary(lang) and is_binary(value) ->
if is_good_locale_code?(lang) do
Map.put(acc, lang, value)
else
acc
end
_, acc ->
acc
end)
{:ok, data}
end
+ def cast(_), do: :error
+
defp is_good_locale_code?(code) do
code
|> String.codepoints()
|> Enum.all?(&valid_char?/1)
end
# [a-zA-Z0-9-]
defp valid_char?(char) do
("a" <= char and char <= "z") or
("A" <= char and char <= "Z") or
("0" <= char and char <= "9") or
char == "-"
end
- def cast(_), do: :error
-
def dump(data), do: {:ok, data}
def load(data), do: {:ok, data}
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Wed, Nov 18, 7:00 AM (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1840196
Default Alt Text
(1 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline