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.

slack: Requote image_url in render_attachment.

Mateusz Manderae65fb2d05191
diff --git a/zerver/data_import/slack_message_conversion.py b/zerver/data_import/slack_message_conversion.py
index 53856f392bc..6612fb4dace 100644
--- a/zerver/data_import/slack_message_conversion.py
+++ b/zerver/data_import/slack_message_conversion.py
@@ -5,6 +5,7 @@ from typing import Any, Literal, TypeAlias, TypedDict, cast
import regex
from django.core.exceptions import ValidationError
+from requests.utils import requote_uri
from zerver.lib.types import Validator
from zerver.lib.validator import (
@@ -423,8 +424,13 @@ def render_attachment(attachment: WildValue) -> str:
pieces.append("\n".join(fields))
if attachment.get("blocks"):
pieces += map(render_block, attachment["blocks"])
- if attachment.get("image_url"):
- pieces.append("[]({})".format(attachment["image_url"].tame(check_url)))
+ if image_url_wv := attachment.get("image_url"):
+ try:
+ image_url = image_url_wv.tame(check_url)
+ except ValidationError: # nocoverage
+ image_url = image_url_wv.tame(check_string)
+ image_url = requote_uri(image_url)
+ pieces.append(f"[]({image_url})")
if attachment.get("footer"):
pieces.append(attachment["footer"].tame(check_string))
if attachment.get("ts"):