logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma
commit: b5d486d9ac40c051c23d23ef5a48685d08127904
parent: 9305e241cbbf78c634576dec58fb383563b39c58
Author: lambda <lain@soykaf.club>
Date:   Tue,  2 Apr 2019 10:51:33 +0000

Merge branch 'fix/nicknames-beginning-with-numbers' into 'develop'

Fix account lookup for nicknames beginning with numbers

See merge request pleroma/pleroma!1003

Diffstat:

Mlib/pleroma/flake_id.ex2+-
Mtest/user_test.exs7+++++++
Mtest/web/mastodon_api/mastodon_api_controller_test.exs26++++++++++++++++++++++++++
3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/lib/pleroma/flake_id.ex b/lib/pleroma/flake_id.ex @@ -46,7 +46,7 @@ defmodule Pleroma.FlakeId do def from_string(string) when is_binary(string) and byte_size(string) < 18 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 end end diff --git a/test/user_test.exs b/test/user_test.exs @@ -200,6 +200,13 @@ defmodule Pleroma.UserTest do refute User.following?(followed, user) 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 @full_user_data %{ bio: "A guy", diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -2265,4 +2265,30 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert link_header =~ ~r/max_id=#{notification1.id}/ 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