Files
hermes-agent/tests/hermes_cli/test_session_export_html_escape.py
T
teknium1 4b67380698 test: purge low-value tests, lane py13 (371 removed)
Change-detectors, tautologies, source-reading tests, redundant duplicates,
mock-echo tests and dead/unrunnable tests. Per-test rationale in the lane
ledger (category + reason for every removal).
2026-09-23 03:15:26 -07:00

29 lines
895 B
Python

import re
from hermes_cli.session_export_html import _generate_messages_html
def test_role_is_escaped_in_html_export():
messages = [
{
"role": "<img src=x onerror=alert(document.domain)>",
"content": "hello",
"timestamp": 1700000000,
}
]
html = _generate_messages_html(messages)
assert "<img src=x onerror=alert(document.domain)>" not in html
assert "&lt;img src=x onerror=alert(document.domain)&gt;" in html
# The class attribute must remain a single, well-formed token: a crafted
# role must not break out of it nor split into several unintended classes.
class_value = re.search(r'class="(message message-[^"]*active)"', html)
assert class_value is not None
assert " message-" in class_value.group(1) # exactly one message-<role> class
assert class_value.group(1).count("message-") == 1