From f3605e3982863cd8192ece333adbb9d068bbfb3e Mon Sep 17 00:00:00 2001 From: Andrew Marwood Date: Tue, 5 Apr 2022 21:44:44 +1000 Subject: [PATCH] fix(email) insert carriage return at end of pars (#2331) --- .../publish/formatters/email_formatter.py | 4 ++- .../formatters/email_formatter_test.py | 30 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/superdesk/publish/formatters/email_formatter.py b/superdesk/publish/formatters/email_formatter.py index c08ebb2d1f..50da11c64d 100644 --- a/superdesk/publish/formatters/email_formatter.py +++ b/superdesk/publish/formatters/email_formatter.py @@ -59,7 +59,9 @@ def format(self, article, subscriber, codes=None): if formatted_article.get("dateline", {}).get("text"): # If there is a dateline inject it into the body self._inject_dateline(formatted_article) - doc["message_html"] = render_template("email_article_body.html", article=formatted_article) + doc["message_html"] = render_template("email_article_body.html", article=formatted_article).replace( + "

", "

\r" + ) else: doc["message_html"] = None doc["message_text"] = render_template("email_article_body.txt", article=formatted_article) diff --git a/tests/publish/formatters/email_formatter_test.py b/tests/publish/formatters/email_formatter_test.py index 0884880bc8..03a3fee58f 100644 --- a/tests/publish/formatters/email_formatter_test.py +++ b/tests/publish/formatters/email_formatter_test.py @@ -58,7 +58,7 @@ def test_formatter(self): " take \n" '
\n
Very good story' "
\nCan of beans\n
joe\n
\n" - "

BERN, July 13 - The story body of the story so far

\n
\n" + "

BERN, July 13 - The story body of the story so far

\r\n
\n" "AAP aa/bb\n\n\n", ) self.assertEqual( @@ -130,7 +130,7 @@ def test_no_place_formatter(self): " take \n" '
\n
Very good story' "
\nCan of beans\n
joe\n
\n" - "

BERN, July 13 - The story body of the story so far

\n
\n" + "

BERN, July 13 - The story body of the story so far

\r\n
\n" "AAP aa/bb\n\n\n", ) self.assertEqual( @@ -175,7 +175,7 @@ def test_none_place_formatter(self): " take \n" '
\n
Very good story' "
\nCan of beans\n
joe\n
\n" - "

BERN, July 13 - The story body of the story so far

\n
\n" + "

BERN, July 13 - The story body of the story so far

\r\n
\n" "AAP aa/bb\n\n\n", ) self.assertEqual( @@ -219,7 +219,7 @@ def test_none_takekey_ednote(self): "Published At : Fri Jan 30 03:40:56 2015\n
\nslugline" " \n
\n" "\nCan of beans\n
joe\n
\n" - "

BERN, July 13 - The story body of the story so far

\n
\n" + "

BERN, July 13 - The story body of the story so far

\r\n
\n" "AAP aa/bb\n\n\n", ) self.assertEqual( @@ -313,3 +313,25 @@ def test_featuremedia(self): seq, doc = self.formatter.format(article, {"name": "Test Subscriber"})[0] item = json.loads(doc) self.assertEqual(item["renditions"]["viewImage"]["media"], "5c11ece81d41c89113ed202b") + + def test_unbroken_html(self): + article = { + "source": "AAP", + "anpa_take_key": "take", + "subject": [{"qcode": "02011001"}], + "format": "HTML", + "type": "text", + "body_html": "

abcdefghijklmnopqrstuvwxyz

" * 2, + "word_count": "1", + "priority": 1, + "place": [{"qcode": "VIC", "name": "VIC"}], + "genre": [], + "sign_off": "aa/bb", + } + article["versioncreated"] = datetime.datetime( + year=2017, month=2, day=24, hour=16, minute=40, second=56, tzinfo=utc + ) + seq, doc = self.formatter.format(article, {"name": "Test Subscriber"})[0] + + item = json.loads(doc) + self.assertIn("

abcdefghijklmnopqrstuvwxyz

\r\n", item.get("message_html"))