mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
use html.escape instead of some self build functions
This commit is contained in:
parent
e3c1bde793
commit
073c3c8fed
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from html import escape
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
@ -198,12 +199,7 @@ class MailDocumentParser(DocumentParser):
|
|||||||
text = "\n".join([str(e) for e in text])
|
text = "\n".join([str(e) for e in text])
|
||||||
if type(text) != str:
|
if type(text) != str:
|
||||||
text = str(text)
|
text = str(text)
|
||||||
text = text.replace("&", "&")
|
text = escape(text)
|
||||||
text = text.replace("<", "<")
|
|
||||||
text = text.replace(">", ">")
|
|
||||||
text = text.replace(" ", " ")
|
|
||||||
text = text.replace("'", "'")
|
|
||||||
text = text.replace('"', """)
|
|
||||||
text = clean(text)
|
text = clean(text)
|
||||||
text = linkify(text, parse_email=True)
|
text = linkify(text, parse_email=True)
|
||||||
text = text.replace("\n", "<br>")
|
text = text.replace("\n", "<br>")
|
||||||
|
@ -364,11 +364,13 @@ class TestParser(TestCase):
|
|||||||
def test_mail_to_html(self):
|
def test_mail_to_html(self):
|
||||||
mail = self.parser.get_parsed(os.path.join(self.SAMPLE_FILES, "html.eml"))
|
mail = self.parser.get_parsed(os.path.join(self.SAMPLE_FILES, "html.eml"))
|
||||||
html_handle = self.parser.mail_to_html(mail)
|
html_handle = self.parser.mail_to_html(mail)
|
||||||
|
html_received = html_handle.read()
|
||||||
|
|
||||||
with open(
|
with open(
|
||||||
os.path.join(self.SAMPLE_FILES, "html.eml.html"),
|
os.path.join(self.SAMPLE_FILES, "html.eml.html"),
|
||||||
) as html_expected_handle:
|
) 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.requests.post")
|
||||||
@mock.patch("paperless_mail.parsers.MailDocumentParser.mail_to_html")
|
@mock.patch("paperless_mail.parsers.MailDocumentParser.mail_to_html")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user