From 1fe0f6e20b4b01f66615aa8da9376f1daeb31991 Mon Sep 17 00:00:00 2001
From: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
Date: Tue, 16 Jul 2024 14:15:43 +0200
Subject: [PATCH] fix: handle invalid images in HTML (#27095)
* fix: handle invalid image
* refactor: simplify broken image replacement
* fix: add alt attribute to broken image
---
frappe/core/doctype/file/test_file.py | 21 ++++++++++++++++++++-
frappe/core/doctype/file/utils.py | 12 +++++++++++-
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/frappe/core/doctype/file/test_file.py b/frappe/core/doctype/file/test_file.py
index 6c9b9f5872..03a8927dac 100644
--- a/frappe/core/doctype/file/test_file.py
+++ b/frappe/core/doctype/file/test_file.py
@@ -17,7 +17,7 @@ from frappe.core.api.file import (
unzip_file,
)
from frappe.core.doctype.file.exceptions import FileTypeNotAllowed
-from frappe.core.doctype.file.utils import get_extension
+from frappe.core.doctype.file.utils import get_corrupted_image_msg, get_extension
from frappe.desk.form.utils import add_comment
from frappe.exceptions import ValidationError
from frappe.tests.utils import FrappeTestCase, change_settings
@@ -768,6 +768,25 @@ class TestFileUtils(FrappeTestCase):
)
self.assertRegex(communication.content, r"
")
+ def test_broken_image(self):
+ """Ensure that broken inline images don't cause errors."""
+ is_private = not frappe.get_meta("Communication").make_attachments_public
+ communication = frappe.get_doc(
+ doctype="Communication",
+ communication_type="Communication",
+ communication_medium="Email",
+ content='
