Bypass the filter based on content-type as well in case a webp image is uploaded...
authorMark Felder <feld@FreeBSD.org>
Fri, 4 Sep 2020 22:56:05 +0000 (17:56 -0500)
committerrinpatch <rinpatch@sdf.org>
Tue, 8 Sep 2020 09:29:38 +0000 (12:29 +0300)
lib/pleroma/upload/filter/exiftool.ex
test/upload/filter/exiftool_test.exs

index 94d12c01b16c7cd519a8950a4afb61cb55c490ae..b07a671ac0b296656fdae75dc473cca7a46006b4 100644 (file)
@@ -10,8 +10,11 @@ defmodule Pleroma.Upload.Filter.Exiftool do
   @behaviour Pleroma.Upload.Filter
 
   @spec filter(Pleroma.Upload.t()) :: {:ok, any()} | {:error, String.t()}
+
+  # webp is not compatible with exiftool at this time
+  def filter(%Pleroma.Upload{content_type: "image/webp"}), do: {:ok, :noop}
+
   def filter(%Pleroma.Upload{name: file, tempfile: path, content_type: "image" <> _}) do
-    # webp is not compatible with exiftool at this time
     if Regex.match?(~r/\.(webp)$/i, file) do
       {:ok, :noop}
     else
index fe24036d93411b46532a9d9d1eb63c250a42f149..84a3f8b300f0054ed8d5437c4a389fddf1f8eb3e 100644 (file)
@@ -34,11 +34,15 @@ defmodule Pleroma.Upload.Filter.ExiftoolTest do
   test "verify webp files are skipped" do
     upload = %Pleroma.Upload{
       name: "sample.webp",
-      content_type: "image/webp",
-      path: Path.absname("/dev/null"),
-      tempfile: Path.absname("/dev/null")
+      content_type: "image/webp"
+    }
+
+    bad_type = %Pleroma.Upload{
+      name: "sample.webp",
+      content_type: "image/jpeg"
     }
 
     assert Filter.Exiftool.filter(upload) == {:ok, :noop}
+    assert Filter.Exiftool.filter(bad_type) == {:ok, :noop}
   end
 end