Fixes #415. Properly handle nil and empty string by User.parse_bio
authorraeno <just.raeno@gmail.com>
Sun, 9 Dec 2018 21:01:43 +0000 (01:01 +0400)
committerraeno <just.raeno@gmail.com>
Sun, 9 Dec 2018 21:01:43 +0000 (01:01 +0400)
lib/pleroma/user.ex
test/web/twitter_api/twitter_api_test.exs

index a290db04adb91135c321c6ffec2a70e17da9c192..5d05dddfa2bc2de120879c6c81fac2e4c7901d0b 100644 (file)
@@ -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)
 
index 05f832de09ff490b60065d760b17a72c7eb6c1d4..522cfd11d182a98327dc0041a510f3e336c417d4 100644 (file)
@@ -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"
     }