Merge branch 'remake-remodel' into develop
[akkoma] / lib / pleroma / user / search.ex
index 6b55df483b76944ba6276f25033ea30f76841628..cec59c372b835f76c2b54f0e68e814e6282c7366 100644 (file)
@@ -1,5 +1,5 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.User.Search do
@@ -33,9 +33,15 @@ defmodule Pleroma.User.Search do
     # Strip the beginning @ off if there is a query
     query_string = String.trim_leading(query_string, "@")
 
-    with [name, domain] <- String.split(query_string, "@"),
-         formatted_domain <- String.replace(domain, ~r/[!-\-|@|[-`|{-~|\/|:|\s]+/, "") do
-      name <> "@" <> to_string(:idna.encode(formatted_domain))
+    with [name, domain] <- String.split(query_string, "@") do
+      encoded_domain =
+        domain
+        |> String.replace(~r/[!-\-|@|[-`|{-~|\/|:|\s]+/, "")
+        |> String.to_charlist()
+        |> :idna.encode()
+        |> to_string()
+
+      name <> "@" <> encoded_domain
     else
       _ -> query_string
     end