Browse Source

Improve string_to_elixir_types/1 with guards

feature/2295-email-mention-notification
Mark Felder 3 years ago
parent
commit
c3b8c77967
1 changed files with 5 additions and 3 deletions
  1. +5
    -3
      lib/pleroma/config_db.ex

+ 5
- 3
lib/pleroma/config_db.ex View File

@@ -327,7 +327,7 @@ defmodule Pleroma.ConfigDB do

@spec string_to_elixir_types(String.t()) ::
atom() | Regex.t() | module() | String.t() | no_return()
def string_to_elixir_types("~r" <> _pattern = regex) do
def string_to_elixir_types("~r" <> _pattern = regex) when is_binary(regex) do
pattern =
~r/^~r(?'delimiter'[\/|"'([{<]{1})(?'pattern'.+)[\/|"')\]}>]{1}(?'modifier'[uismxfU]*)/u

@@ -341,9 +341,9 @@ defmodule Pleroma.ConfigDB do
end
end

def string_to_elixir_types(":" <> atom), do: String.to_atom(atom)
def string_to_elixir_types(":" <> atom) when is_binary(atom), do: String.to_atom(atom)

def string_to_elixir_types(value) do
def string_to_elixir_types(value) when is_binary(value) do
if module_name?(value) do
String.to_existing_atom("Elixir." <> value)
else
@@ -351,6 +351,8 @@ defmodule Pleroma.ConfigDB do
end
end

def string_to_elixir_types(value) when is_atom(value), do: value

defp parse_host("localhost"), do: :localhost

defp parse_host(host) do


Loading…
Cancel
Save