"""Safe post content (protocol/content.py): escaping, and the weekly summary template built on top of it (publishing/weekly.py's build_content).""" import pytest from scrobbler.federation.protocol import content from scrobbler.federation.publishing.weekly import build_content from scrobbler.services.stats import TopItem def test_escape_neutralises_markup(): assert content.escape("") == "<script>alert(1)</script>" def test_escape_handles_ampersands_without_double_escaping(): assert content.escape("Earth, Wind & Fire") == "Earth, Wind & Fire" def test_escape_passes_through_emoji_and_non_latin_text(): # Emoji and non-Latin scripts aren't HTML-significant, so they pass through untouched. assert content.escape("Björk 🎵 坂本龍一") == "Björk 🎵 坂本龍一" def test_escape_does_not_break_right_to_left_text(): name = "محمد <عبده>" # Arabic text with embedded angle brackets escaped = content.escape(name) assert "<" not in escaped and ">" not in escaped assert "محمد" in escaped # the Arabic letters are untouched def test_paragraph_and_numbered_list_only_use_tags_mastodon_keeps(): assert content.paragraph("hi") == "
hi
" assert content.numbered_list(["a", "b"]) == "