ensure utf-8 nicknames on nickname GETs and user validator #1057
2 changed files with 16 additions and 16 deletions
commit
58ee25bfbb
|
|
@ -1221,29 +1221,25 @@ defmodule Pleroma.User do
|
|||
end
|
||||
end)
|
||||
else
|
||||
:error
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def get_cached_by_nickname_or_id(nickname_or_id, opts \\ []) do
|
||||
if String.valid?(nickname_or_id) do
|
||||
restrict_to_local = Config.get([:instance, :limit_to_local_content])
|
||||
restrict_to_local = Config.get([:instance, :limit_to_local_content])
|
||||
|
floatingghost marked this conversation as resolved
|
||||
|
||||
cond do
|
||||
is_integer(nickname_or_id) or FlakeId.flake_id?(nickname_or_id) ->
|
||||
get_cached_by_id(nickname_or_id) || get_cached_by_nickname(nickname_or_id)
|
||||
cond do
|
||||
is_integer(nickname_or_id) or FlakeId.flake_id?(nickname_or_id) ->
|
||||
get_cached_by_id(nickname_or_id) || get_cached_by_nickname(nickname_or_id)
|
||||
|
||||
restrict_to_local == false or not String.contains?(nickname_or_id, "@") ->
|
||||
get_cached_by_nickname(nickname_or_id)
|
||||
restrict_to_local == false or not String.contains?(nickname_or_id, "@") ->
|
||||
get_cached_by_nickname(nickname_or_id)
|
||||
|
||||
restrict_to_local == :unauthenticated and match?(%User{}, opts[:for]) ->
|
||||
get_cached_by_nickname(nickname_or_id)
|
||||
restrict_to_local == :unauthenticated and match?(%User{}, opts[:for]) ->
|
||||
get_cached_by_nickname(nickname_or_id)
|
||||
|
||||
true ->
|
||||
nil
|
||||
end
|
||||
else
|
||||
:error
|
||||
true ->
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1255,7 +1251,7 @@ defmodule Pleroma.User do
|
|||
Repo.get_by(User, nickname: local_nickname(nickname))
|
||||
end
|
||||
else
|
||||
:error
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -93,5 +93,9 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UserValidator do
|
|||
end
|
||||
end
|
||||
|
||||
defp validate_nickname(%{"preferredUsername" => _nick}) do
|
||||
{:error, "Nickname is not a valid string"}
|
||||
end
|
||||
|
||||
defp validate_nickname(_), do: :ok
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue
Since
FlakeIdcan handle this and id-type arguments are presumably much more common it might be good to optimise this by only testingString.validif there was no id match. E.g. something like:Though it might be nicer to split the "allowed to lookup" checks handled in the
condinto a private function returning a boolean and then also handle this as just anotherwithclause:i just removed the check in nickname_by_id and let it live in the get_cached_by_nickname which should be suitable