forked from YokaiRick/akkoma
Fix account lookup for nicknames beginning with numbers
This commit is contained in:
parent
9305e241cb
commit
95c92c49c9
3 changed files with 34 additions and 1 deletions
|
@ -46,7 +46,7 @@ def from_string(<<_::integer-size(128)>> = flake), do: flake
|
||||||
|
|
||||||
def from_string(string) when is_binary(string) and byte_size(string) < 18 do
|
def from_string(string) when is_binary(string) and byte_size(string) < 18 do
|
||||||
case Integer.parse(string) do
|
case Integer.parse(string) do
|
||||||
{id, _} -> <<0::integer-size(64), id::integer-size(64)>>
|
{id, ""} -> <<0::integer-size(64), id::integer-size(64)>>
|
||||||
_ -> nil
|
_ -> nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -200,6 +200,13 @@ test "test if a user is following another user" do
|
||||||
refute User.following?(followed, user)
|
refute User.following?(followed, user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "fetches correct profile for nickname beginning with number" do
|
||||||
|
# Use old-style integer ID to try to reproduce the problem
|
||||||
|
user = insert(:user, %{id: 1080})
|
||||||
|
userwithnumbers = insert(:user, %{nickname: "#{user.id}garbage"})
|
||||||
|
assert userwithnumbers == User.get_cached_by_nickname_or_id(userwithnumbers.nickname)
|
||||||
|
end
|
||||||
|
|
||||||
describe "user registration" do
|
describe "user registration" do
|
||||||
@full_user_data %{
|
@full_user_data %{
|
||||||
bio: "A guy",
|
bio: "A guy",
|
||||||
|
|
|
@ -2265,4 +2265,30 @@ test "preserves parameters in link headers", %{conn: conn} do
|
||||||
assert link_header =~ ~r/max_id=#{notification1.id}/
|
assert link_header =~ ~r/max_id=#{notification1.id}/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "accounts fetches correct account for nicknames beginning with numbers", %{conn: conn} do
|
||||||
|
# Need to set an old-style integer ID to reproduce the problem
|
||||||
|
# (these are no longer assigned to new accounts but were preserved
|
||||||
|
# for existing accounts during the migration to flakeIDs)
|
||||||
|
user_one = insert(:user, %{id: 1212})
|
||||||
|
user_two = insert(:user, %{nickname: "#{user_one.id}garbage"})
|
||||||
|
|
||||||
|
resp_one =
|
||||||
|
conn
|
||||||
|
|> get("/api/v1/accounts/#{user_one.id}")
|
||||||
|
|
||||||
|
resp_two =
|
||||||
|
conn
|
||||||
|
|> get("/api/v1/accounts/#{user_two.nickname}")
|
||||||
|
|
||||||
|
resp_three =
|
||||||
|
conn
|
||||||
|
|> get("/api/v1/accounts/#{user_two.id}")
|
||||||
|
|
||||||
|
acc_one = json_response(resp_one, 200)
|
||||||
|
acc_two = json_response(resp_two, 200)
|
||||||
|
acc_three = json_response(resp_three, 200)
|
||||||
|
refute acc_one == acc_two
|
||||||
|
assert acc_two == acc_three
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue