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.

markdown: Use re-exported guess_type to ensure adding EXTRA_MIME_TYPES.

Anders Kaseorgb8f8056f5681
diff --git a/tools/semgrep-py.yml b/tools/semgrep-py.yml
index d8cef8b91d0..4bd0d135c1f 100644
--- a/tools/semgrep-py.yml
+++ b/tools/semgrep-py.yml
@@ -52,6 +52,19 @@ rules:
languages: [python]
severity: ERROR
+ - id: use-wrapped-mimetypes
+ pattern-either:
+ - pattern: mimetypes.guess_type
+ - pattern: mimetypes.guess_file_type
+ - pattern: mimetypes.guess_all_extensions
+ - pattern: mimetypes.guess_extension
+ message: Use zerver.lib.mime_types (to ensure our EXTRA_MIME_TYPES are added)
+ languages: [python]
+ severity: ERROR
+ paths:
+ exclude:
+ - zerver/lib/mime_types.py
+
- id: dont-import-models-in-migrations
patterns:
- pattern-not: from zerver.lib.migrate import $X
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py
index bb946d71e63..dc8f02b0039 100644
--- a/zerver/lib/markdown/__init__.py
+++ b/zerver/lib/markdown/__init__.py
@@ -1,7 +1,6 @@
# Zulip's main Markdown implementation. See docs/subsystems/markdown.md for
# detailed documentation on our Markdown syntax.
import logging
-import mimetypes
import re
import time
from collections import deque
@@ -1032,7 +1031,7 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):
if not self.zmd.image_preview_enabled:
return False
- url_type = mimetypes.guess_type(url)[0]
+ url_type = guess_type(url)[0]
# Support only video formats (containers) that are supported cross-browser and cross-device. As per
# https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Containers#index_of_media_container_formats_file_types
# MP4 and WebM are the only formats that are widely supported.