"""Tests for HTML utility functions."""
from unittest.mock import patch
from src.utils.html import escape_html
class TestEscapeHtml:
"""Tests for escape_html function."""
def test_escapes_angle_brackets(self) -> None:
"""Verify < and > are escaped."""
assert "<" in escape_html("
")
assert ">" in escape_html("
")
def test_escapes_ampersand(self) -> None:
"""Verify & is escaped."""
assert "&" in escape_html("a & b")
def test_escapes_double_quotes(self) -> None:
"""Verify double quotes are escaped."""
assert """ in escape_html('say "hello"')
def test_escapes_single_quotes(self) -> None:
"""Verify single quotes are escaped."""
assert "'" in escape_html("it's")
def test_safe_strings_unchanged(self) -> None:
"""Verify safe strings pass through unmodified."""
assert escape_html("Hello World") == "Hello World"
assert escape_html("abc123") == "abc123"
assert escape_html("") == ""
class TestSafeHeading:
"""Tests for safe_heading function."""
def test_escapes_xss_payload(self) -> None:
"""Verify XSS payloads are escaped in heading output."""
with patch("src.utils.html.st") as mock_st:
from src.utils.html import safe_heading
safe_heading("")
call_args = mock_st.markdown.call_args
rendered_html = call_args[0][0]
assert "