Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/platforms/email/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ def _strip_html(html: str) -> str:
text = re.sub(r"</p>", "\n", text, flags=re.IGNORECASE)
text = re.sub(r"<[^>]+>", "", text)
text = re.sub(r"&nbsp;", " ", text)
text = re.sub(r"&amp;", "&", text)
text = re.sub(r"&lt;", "<", text)
text = re.sub(r"&gt;", ">", text)
# Decode ampersands last so &amp;lt; remains literal &lt;, not markup-like text.
text = re.sub(r"&amp;", "&", text)
text = re.sub(r"\n{3,}", "\n\n", text)
return text.strip()

Expand Down
8 changes: 8 additions & 0 deletions tests/gateway/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ def test_strip_html_basic(self):
self.assertNotIn("<p>", result)
self.assertNotIn("<b>", result)

def test_strip_html_does_not_double_decode_entities(self):
from plugins.platforms.email.adapter import _strip_html

self.assertEqual(
_strip_html("The token is &amp;lt;APIKEY&amp;gt;"),
"The token is &lt;APIKEY&gt;",
)


class TestExtractTextBody(unittest.TestCase):
"""Test email body extraction from different message formats."""
Expand Down
Loading