From: raeno Date: Sun, 9 Dec 2018 21:01:43 +0000 (+0400) Subject: Fixes #415. Properly handle nil and empty string by User.parse_bio X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=9ba4a1c5fe1cbc6f028f04be9c953a189a08bd09;p=akkoma Fixes #415. Properly handle nil and empty string by User.parse_bio --- 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest 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" }