Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

thumbnail: Tolerate a missing content-type in missing_thumbnails.

Aman Agrawalbcb02f7f780c
diff --git a/zerver/lib/thumbnail.py b/zerver/lib/thumbnail.py
index 0dd5599a7bb..67e65136420 100644
--- a/zerver/lib/thumbnail.py
+++ b/zerver/lib/thumbnail.py
@@ -313,8 +313,7 @@ def missing_thumbnails(
seen_thumbnails.add(StoredThumbnailFormat(**existing_thumbnail))
potential_output_formats = list(THUMBNAIL_OUTPUT_FORMATS)
- assert image_attachment.content_type
- if bare_content_type(image_attachment.content_type) not in INLINE_MIME_TYPES:
+ if needs_transcoded_format(image_attachment):
if image_attachment.original_width_px >= image_attachment.original_height_px:
additional_format = ThumbnailFormat(
TRANSCODED_IMAGE_FORMAT.extension,
diff --git a/zerver/tests/test_thumbnail.py b/zerver/tests/test_thumbnail.py
index 56acdb1a9c4..03ee7986c94 100644
--- a/zerver/tests/test_thumbnail.py
+++ b/zerver/tests/test_thumbnail.py
@@ -735,8 +735,33 @@ class TestStoreThumbnail(ZulipTestCase):
)
image_attachment.content_type = "image/png"
self.assertEqual(get_transcoded_format(image_attachment), None)
+ # A null or empty content-type is judged inline.
image_attachment.content_type = None
self.assertEqual(get_transcoded_format(image_attachment), None)
+ image_attachment.content_type = ""
+ self.assertEqual(get_transcoded_format(image_attachment), None)
+
+ def test_missing_thumbnails_missing_content_type(self) -> None:
+ # A null or empty content-type (some old uploads) must not
+ # crash; it is judged inline, like get_transcoded_format.
+ image_attachment = ImageAttachment(
+ path_id="example",
+ original_width_px=150,
+ original_height_px=100,
+ frames=1,
+ thumbnail_metadata=[],
+ content_type="image/tiff",
+ )
+ still_webp = ThumbnailFormat("webp", 100, 75, animated=False, opts="Q=90")
+ transcoded = ThumbnailFormat("webp", 4032, 3024, animated=False)
+ with self.thumbnail_formats(still_webp):
+ # A known non-inline type gets the extra transcoded format.
+ self.assertEqual(missing_thumbnails(image_attachment), [still_webp, transcoded])
+
+ # A missing content-type does not, and does not crash.
+ for missing_content_type in (None, ""):
+ image_attachment.content_type = missing_content_type
+ self.assertEqual(missing_thumbnails(image_attachment), [still_webp])
def test_maybe_thumbnail_from_stream(self) -> None:
# If we put the file in place directly (e.g. simulating a