]> granicus.if.org Git - ejabberd/commitdiff
Improve validation of 'convert' option
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 15 Jan 2018 22:06:20 +0000 (01:06 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 15 Jan 2018 22:06:20 +0000 (01:06 +0300)
src/mod_avatar.erl

index b72946df44648cd4add6c9efbb0c0cc611df0044..778794e1acdb5d4378e7de2dac65c2f081530b91 100644 (file)
@@ -407,18 +407,30 @@ decode_mime_type(MimeType) ->
 encode_mime_type(Type) ->
     <<"image/", (atom_to_binary(Type, latin1))/binary>>.
 
-warn(Format) ->
-    ?WARNING_MSG("ejabberd is not compiled with ~p support", [Format]).
+-spec fail(atom()) -> no_return().
+fail(Format) ->
+    FormatS = case Format of
+                 webp -> "WebP";
+                 png -> "PNG";
+                 jpeg -> "JPEG";
+                 gif -> "GIF";
+                 _ -> ""
+             end,
+    if FormatS /= "" ->
+           ?WARNING_MSG("ejabberd is not compiled with ~s support", [FormatS]);
+       true ->
+           ok
+    end,
+    erlang:error(badarg).
 
-mod_opt_type({convert, From}) when From == webp; From == jpeg;
-                                  From == png; From == gif ->
+mod_opt_type({convert, From}) ->
     fun(To) when is_atom(To), To /= From ->
-           case eimp:is_supported(From) of
+           case eimp:is_supported(From) orelse From == default of
                false ->
-                   warn(From);
+                   fail(From);
                true ->
                    case eimp:is_supported(To) of
-                       false -> warn(To);
+                       false -> fail(To);
                        true -> To
                    end
            end