From 9ba4a1c5fe1cbc6f028f04be9c953a189a08bd09 Mon Sep 17 00:00:00 2001 From: raeno Date: Mon, 10 Dec 2018 01:01:43 +0400 Subject: [PATCH] Fixes #415. Properly handle nil and empty string by User.parse_bio --- lib/pleroma/user.ex | 6 +++++- test/web/twitter_api/twitter_api_test.exs | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index a290db04a..5d05dddfa 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -804,7 +804,11 @@ def wait_and_refresh(timeout, %User{} = a, %User{} = b) do end end - def parse_bio(bio, user \\ %User{info: %{source_data: %{}}}) do + def parse_bio(bio, user \\ %User{info: %{source_data: %{}}}) + def parse_bio(nil, user), do: "" + def parse_bio(bio, user) when bio == "", do: bio + + def parse_bio(bio, user) do mentions = Formatter.parse_mentions(bio) tags = Formatter.parse_tags(bio) diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 05f832de0..522cfd11d 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -246,7 +246,24 @@ test "it registers a new user and returns the user." do "nickname" => "lain", "email" => "lain@wired.jp", "fullname" => "lain iwakura", - "bio" => "close the world.", + "password" => "bear", + "confirm" => "bear" + } + + {:ok, user} = TwitterAPI.register_user(data) + + fetched_user = Repo.get_by(User, nickname: "lain") + + assert UserView.render("show.json", %{user: user}) == + UserView.render("show.json", %{user: fetched_user}) + end + + test "it registers a new user with empty string in bio and returns the user." do + data = %{ + "nickname" => "lain", + "email" => "lain@wired.jp", + "fullname" => "lain iwakura", + "bio" => "", "password" => "bear", "confirm" => "bear" }