]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
use html.escape instead of some self build functions
authorphail <phail@hacknology.de>
Sun, 20 Nov 2022 11:36:49 +0000 (12:36 +0100)
committerphail <phail@hacknology.de>
Sun, 20 Nov 2022 11:36:49 +0000 (12:36 +0100)
src/paperless_mail/parsers.py
src/paperless_mail/tests/test_parsers.py

index da0cf96b9f4cb0bbe3ce3425971a7db6b47bf60d..c4ecaf8615b367c871c8e21aac1fbed46a9fa4ad 100644 (file)
@@ -1,5 +1,6 @@
 import os
 import re
+from html import escape
 from io import BytesIO
 from io import StringIO
 
@@ -198,12 +199,7 @@ class MailDocumentParser(DocumentParser):
                 text = "\n".join([str(e) for e in text])
             if type(text) != str:
                 text = str(text)
-            text = text.replace("&", "&amp;")
-            text = text.replace("<", "&lt;")
-            text = text.replace(">", "&gt;")
-            text = text.replace("  ", " &nbsp;")
-            text = text.replace("'", "&apos;")
-            text = text.replace('"', "&quot;")
+            text = escape(text)
             text = clean(text)
             text = linkify(text, parse_email=True)
             text = text.replace("\n", "<br>")
index 4123e1cc8c622fb5f44f253aa10b654eb41629bb..1a348b472b8aeec48b3c33077029ebdf6b34ab05 100644 (file)
@@ -364,11 +364,13 @@ class TestParser(TestCase):
     def test_mail_to_html(self):
         mail = self.parser.get_parsed(os.path.join(self.SAMPLE_FILES, "html.eml"))
         html_handle = self.parser.mail_to_html(mail)
+        html_received = html_handle.read()
 
         with open(
             os.path.join(self.SAMPLE_FILES, "html.eml.html"),
         ) as html_expected_handle:
-            self.assertHTMLEqual(html_expected_handle.read(), html_handle.read())
+            html_expected = html_expected_handle.read()
+            self.assertHTMLEqual(html_expected, html_received)
 
     @mock.patch("paperless_mail.parsers.requests.post")
     @mock.patch("paperless_mail.parsers.MailDocumentParser.mail_to_html")