From 6784c039c6d22e13cc59f941b19bff0ef9c799e1 Mon Sep 17 00:00:00 2001 From: Andrew Marwood Date: Wed, 2 Aug 2023 15:33:43 +1000 Subject: [PATCH] fix remove all embeds for multiple embeds (#2462) --- superdesk/editor_utils.py | 4 +-- .../formatters/email_formatter_test.py | 32 ++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/superdesk/editor_utils.py b/superdesk/editor_utils.py index 71131c219c..cdcc4b9c50 100644 --- a/superdesk/editor_utils.py +++ b/superdesk/editor_utils.py @@ -168,8 +168,8 @@ def insert(self, index, value): self._mapping[value.key] = value.data def clear(self): - for idx, kk in enumerate(self._ranges): - del self[kk.get("key")] + for idx, _range in enumerate(self._ranges): + del self[idx] class Block: diff --git a/tests/publish/formatters/email_formatter_test.py b/tests/publish/formatters/email_formatter_test.py index 5fed0d883f..5e4f47478f 100644 --- a/tests/publish/formatters/email_formatter_test.py +++ b/tests/publish/formatters/email_formatter_test.py @@ -368,6 +368,24 @@ def test_remove_embedded_content(self): "entityRanges": [{"offset": 0, "length": 1, "key": 0}], "data": {}, }, + { + "key": "8e23v", + "text": " ", + "type": "atomic", + "depth": 0, + "inlineStyleRanges": [], + "entityRanges": [{"offset": 0, "length": 1, "key": 1}], + "data": {}, + }, + { + "key": "an34p", + "text": " ", + "type": "atomic", + "depth": 0, + "inlineStyleRanges": [], + "entityRanges": [{"offset": 0, "length": 1, "key": 2}], + "data": {}, + }, { "key": "ambpd", "text": "post amble", @@ -378,7 +396,19 @@ def test_remove_embedded_content(self): "data": {}, }, ], - "entityMap": {"0": {"type": "MEDIA", "mutability": "MUTABLE", "data": {"media": {}}}}, + "entityMap": { + "0": {"type": "MEDIA", "mutability": "MUTABLE", "data": {"media": {}}}, + "1": { + "type": "EMBED", + "mutability": "MUTABLE", + "data": {"data": {"html": "
"}}, + }, + "2": { + "type": "EMBED", + "mutability": "MUTABLE", + "data": {"data": {"html": "
"}}, + }, + }, } ] }