"""HTML sanitization (SPEC §6.4, §10.4, I-8).""" from __future__ import annotations import uuid import pytest from app.indexer.sanitize import sanitize_html MID = uuid.uuid4() def test_scripts_and_handlers_are_removed() -> None: html = '
',
"
',
# Squeezed to a pixel by max-width, its height following.
'Hello
{tag}Bye
" for allow in (False, True): result = sanitize_html(html, MID, allow_remote_images=allow) assert result.trackers_blocked == 1 assert "
',
'
',
'
',
# Attributes say 1x1, the style draws it full width.
'x
{tag}", MID, allow_remote_images=True) assert result.trackers_blocked == 0 assert "
'
result = sanitize_html(f"x
{tag}", MID, allow_remote_images=True) assert result.trackers_blocked == 0 css = f'
'
assert sanitize_html(css, MID, allow_remote_images=True).trackers_blocked == 0
def test_tracker_blocking_can_be_switched_off() -> None:
tag = 'x
{tag}", MID, allow_remote_images=True, block_trackers=False) assert kept.trackers_blocked == 0 and "t.example.com/o.gif" in kept.html