From 66a04cead34b1772fff93ff359471ff3e4ac93dc Mon Sep 17 00:00:00 2001 From: Ilja Date: Fri, 1 Jul 2022 12:31:34 +0200 Subject: [PATCH] Descriptions from exif data with only whitespeces are considered empty I noticed that pictures taken with Ubuntu-Touch have whitespace in one of the fields This should just be ignored imo --- .../filter/exiftool/read_description.ex | 2 ++ ...ption_and_caption-abstract_whitespaces.jpg | Bin 0 -> 785 bytes .../filter/exiftool/read_description_test.exs | 19 ++++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpg diff --git a/lib/pleroma/upload/filter/exiftool/read_description.ex b/lib/pleroma/upload/filter/exiftool/read_description.ex index a69f79124..03d698a81 100644 --- a/lib/pleroma/upload/filter/exiftool/read_description.ex +++ b/lib/pleroma/upload/filter/exiftool/read_description.ex @@ -35,6 +35,8 @@ defp read_when_empty(_, file, tag) do {tag_content, 0} = System.cmd("exiftool", ["-b", "-s3", tag, file], stderr_to_stdout: true, parallelism: true) + tag_content = String.trim(tag_content) + if tag_content != "" and String.length(tag_content) <= Pleroma.Config.get([:instance, :description_limit]), diff --git a/test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpg b/test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a232fd2a1a467b86a13a4e63e07cf7e59efe4709 GIT binary patch literal 785 zcmex=`H|qMvW5}awt1(JSZA; z@q>zSQc)8pmzcPOq?D?fx`w8fiK&^ng{76Vi>sTvho@I?NN8AiL}XNQN@`kqMrKxV zNoiSmMP*fUOKV$uM`zch$y26In?7UatVN5LEM2yI#mZHiHgDOwZTpU$yAB;ba`f2o z6DLnyx_ss8wd*%--g@}x@sp>|p1*kc>f@)+U%r0({^RE_kiQrim?7SR`wY!rf#!}nhriyG|z-vj^vYv1_* literal 0 HcmV?d00001 diff --git a/test/pleroma/upload/filter/exiftool/read_description_test.exs b/test/pleroma/upload/filter/exiftool/read_description_test.exs index 0b358215c..7389fda47 100644 --- a/test/pleroma/upload/filter/exiftool/read_description_test.exs +++ b/test/pleroma/upload/filter/exiftool/read_description_test.exs @@ -83,6 +83,25 @@ test "Return nil when image description from EXIF data exceeds the maximum lengt {:ok, :filtered, @uploads} end + test "Ignores content with only whitespace" do + uploads = %Pleroma.Upload{ + name: "non-existant.jpg", + content_type: "image/jpeg", + path: + Path.absname( + "test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpg" + ), + tempfile: + Path.absname( + "test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpg" + ), + description: nil + } + + assert Filter.Exiftool.ReadDescription.filter(uploads) == + {:ok, :filtered, uploads} + end + test "Return nil when image description from EXIF data can't be read" do uploads = %Pleroma.Upload{ name: "non-existant.jpg",