summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlja <ilja@ilja.space>2022-07-01 12:31:34 +0200
committerIlja <ilja@ilja.space>2022-07-01 13:47:23 +0200
commit56227ef7ba097c6be39a7e70b67c426a3016e0ab (patch)
tree44190d56621bf1b0272afee9564fee232649f0e2
parent8c761942b1963bff08d98eeb22b84b0f327d68e4 (diff)
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
-rw-r--r--lib/pleroma/upload/filter/exiftool/read_description.ex2
-rw-r--r--test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpgbin0 -> 785 bytes
-rw-r--r--test/pleroma/upload/filter/exiftool/read_description_test.exs19
3 files changed, 21 insertions, 0 deletions
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 @@ defmodule Pleroma.Upload.Filter.Exiftool.ReadDescription 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 000000000..a232fd2a1
--- /dev/null
+++ b/test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpg
Binary files differ
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 @@ defmodule Pleroma.Upload.Filter.Exiftool.ReadDescriptionTest do
{: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",