Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
ms_teams_importer: Fix generating invalid image syntax.
PieterCK0609be36d399
diff --git a/zerver/data_import/microsoft_teams.py b/zerver/data_import/microsoft_teams.pyindex 83c7db662bb..d2bea7e4c53 100644--- a/zerver/data_import/microsoft_teams.py+++ b/zerver/data_import/microsoft_teams.py@@ -210,8 +210,8 @@ MICROSOFT_GRAPH_API_URL = "https://graph.microsoft.com/v1.0{endpoint}"# https://learn.microsoft.com/en-us/graph/api/chatmessagehostedcontent-getHOSTED_CONTENT_GRAPH_API_URL_REGEX = r"https://graph\.microsoft\.com/v1\.0/teams/[^/]+/channels/[^/]+/messages/[^/]+/hostedContents/[^/]+/\$value"-HOSTED_CONTENT_FILE_REGEX = rf"""- \[+HOSTED_CONTENT_MARKDOWN_IMAGE_SYNTAX_REGEX = rf"""+ !\[(?P<file_name>[^\]]+)\]\((?P<api_url>{HOSTED_CONTENT_GRAPH_API_URL_REGEX})@@ -554,7 +554,7 @@ def process_hosted_content_attachments(return AttachmentConversionResult(updated_content=content, upload_records=upload_records)else:updated_content = regex.sub(- HOSTED_CONTENT_FILE_REGEX,+ HOSTED_CONTENT_MARKDOWN_IMAGE_SYNTAX_REGEX,export_file_and_get_zulip_url,content,flags=re.VERBOSE,diff --git a/zerver/tests/test_microsoft_teams_importer.py b/zerver/tests/test_microsoft_teams_importer.pyindex 6bbf7921842..75006763f13 100644--- a/zerver/tests/test_microsoft_teams_importer.py+++ b/zerver/tests/test_microsoft_teams_importer.py@@ -755,16 +755,16 @@ class MicrosoftTeamsImporterUnitTest(MicrosoftTeamsImportTestCase):),# Unprocessed converted htmlMessageFixture(- content="Normal text and an [image](https://graph.microsoft.com/v1.0/teams/1d513e46-d8cd-41db-b84f-381fe5730794/channels/19:[email protected]/messages/1755002994809/hostedContents/aWQ9eF8wLXd1cy1kNi0zZDZkYmNiODA0OGFhODhmMWMxY2Q1N2ZhYWIzYzRhZCx0eXBlPTEsdXJsPWh0dHBzOi8vdXMtYXBpLmFzbS5za3lwZS5jb20vdjEvb2JqZWN0cy8wLXd1cy1kNi0zZDZkYmNiODA0OGFhODhmMWMxY2Q1N2ZhYWIzYzRhZC92aWV3cy9pbWdv/$value)",+ content="Normal text and an ",hosted_content_count=1,is_direct_message_type=False,test_name="text and an image 2",),MessageFixture(content=(- "First [image](https://graph.microsoft.com/v1.0/teams/1d513e46-d8cd-41db-b84f-381fe5730794/channels/19:[email protected]/messages/1755002994809/hostedContents/aWQ9eF8wLXd1cy1kNi0zZDZkYmNiODA0OGFhODhmMWMxY2Q1N2ZhYWIzYzRhZCx0eXBlPTEsdXJsPWh0dHBzOi8vdXMtYXBpLmFzbS5za3lwZS5jb20vdjEvb2JqZWN0cy8wLXd1cy1kNi0zZDZkYmNiODA0OGFhODhmMWMxY2Q1N2ZhYWIzYzRhZC92aWV3cy9pbWdv/$value)"- "Second [image](https://graph.microsoft.com/v1.0/teams/1d513e46-d8cd-41db-b84f-381fe5730794/channels/19:[email protected]/messages/1755002994809/hostedContents/ABC/$value)"- "Third [image](https://graph.microsoft.com/v1.0/teams/1d513e46-d8cd-41db-b84f-381fe5730794/channels/19:[email protected]/messages/1755002994809/hostedContents/DEF/$value)"+ "First "+ "Second "+ "Third "),hosted_content_count=3,is_direct_message_type=False,@@ -806,15 +806,15 @@ class MicrosoftTeamsImporterUnitTest(MicrosoftTeamsImportTestCase):test_name="text only",),MessageFixture(- content="MS Sharepoint attachment URL [image](https://zulipchat.sharepoint.com/sites/Community/Shared Documents/General/wp12245700.jpg)",+ content="MS Sharepoint attachment URL ",hosted_content_count=0,is_direct_message_type=False,test_name="text and other URL",),MessageFixture(content=(- "List all hosted content [invalid](https://graph.microsoft.com/v1.0/teams/FOO/channels/BAZ/hostedContents)"- "Get a hosted content [valid](https://graph.microsoft.com/v1.0/teams/FOO/channels/BAZ/messages/BAR/hostedContents/QUX/$value)"+ "List all hosted content "+ "Get a hosted content "),hosted_content_count=1,is_direct_message_type=False,@@ -822,7 +822,7 @@ class MicrosoftTeamsImporterUnitTest(MicrosoftTeamsImportTestCase):),MessageFixture(content=(- "DM [image](https://graph.microsoft.com/v1.0/chats/{chat-id}/messages/{message-id}/hostedContents/{hosted-content-id}/$value)"+ "DM "),hosted_content_count=0,is_direct_message_type=True,