strip_html: nested tags, malformed HTML, comments, entities. config: unknown key filtering, missing file, mixed valid/invalid.
60 lines
1.4 KiB
Python
60 lines
1.4 KiB
Python
"""Tests for _strip_html edge cases."""
|
|
|
|
from tuimble.app import _strip_html
|
|
|
|
|
|
def test_plain_text_unchanged():
|
|
assert _strip_html("hello world") == "hello world"
|
|
|
|
|
|
def test_simple_tags_stripped():
|
|
assert _strip_html("<b>bold</b>") == "bold"
|
|
|
|
|
|
def test_nested_tags():
|
|
assert _strip_html("<div><p>text</p></div>") == "text"
|
|
|
|
|
|
def test_self_closing_tags():
|
|
assert _strip_html("line<br/>break") == "linebreak"
|
|
|
|
|
|
def test_entities_unescaped():
|
|
assert _strip_html("& < >") == "& < >"
|
|
|
|
|
|
def test_html_entities_in_tags():
|
|
assert _strip_html("<b>&</b>") == "&"
|
|
|
|
|
|
def test_mumble_style_message():
|
|
"""Typical Mumble chat message with anchor tag."""
|
|
msg = '<a href="https://example.com">link text</a> and more'
|
|
assert _strip_html(msg) == "link text and more"
|
|
|
|
|
|
def test_img_tag_with_attributes():
|
|
assert _strip_html('before<img src="x.png" alt="pic"/>after') == "beforeafter"
|
|
|
|
|
|
def test_comment_stripped():
|
|
assert _strip_html("before<!-- comment -->after") == "beforeafter"
|
|
|
|
|
|
def test_empty_string():
|
|
assert _strip_html("") == ""
|
|
|
|
|
|
def test_only_tags():
|
|
assert _strip_html("<br><hr><img/>") == ""
|
|
|
|
|
|
def test_unclosed_tag():
|
|
"""Malformed HTML should not crash."""
|
|
result = _strip_html("<b>unclosed")
|
|
assert "unclosed" in result
|
|
|
|
|
|
def test_multiple_entities():
|
|
assert _strip_html(""quoted"") == '"quoted"'
|