2022-12-20 11:39:45 +00:00
|
|
|
from core.html import html_to_plaintext, sanitize_html
|
2022-11-27 19:09:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_html_to_plaintext():
|
|
|
|
|
|
|
|
assert html_to_plaintext("<p>Hi!</p>") == "Hi!"
|
|
|
|
assert html_to_plaintext("<p>Hi!<br>There</p>") == "Hi!\nThere"
|
|
|
|
assert (
|
|
|
|
html_to_plaintext("<p>Hi!</p>\n\n<p>How are you?</p>") == "Hi!\n\nHow are you?"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert (
|
|
|
|
html_to_plaintext("<p>Hi!</p>\n\n<p>How are<br> you?</p><p>today</p>")
|
|
|
|
== "Hi!\n\nHow are\n you?\n\ntoday"
|
|
|
|
)
|
2022-11-29 05:34:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_sanitize_post():
|
|
|
|
|
2022-12-20 11:39:45 +00:00
|
|
|
assert sanitize_html("<p>Hello!</p>") == "<p>Hello!</p>"
|
|
|
|
assert sanitize_html("<p>It's great</p>") == "<p>It's great</p>"
|
2022-12-20 13:10:35 +00:00
|
|
|
|
|
|
|
# Note that we only want to linkify things with protocol prefixes to prevent
|
|
|
|
# too many false positives.
|
|
|
|
assert sanitize_html("<p>test.com</p>") == "<p>test.com</p>"
|
|
|
|
assert (
|
|
|
|
sanitize_html("<p>https://test.com</p>")
|
|
|
|
== '<p><a href="https://test.com" rel="nofollow">https://test.com</a></p>'
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
sanitize_html("<p>@someone@subdomain.some-domain.com</p>")
|
|
|
|
== "<p>@someone@subdomain.some-domain.com</p>"
|
|
|
|
)
|