From 177d2071e58740255273bafb6d2f07df3dd93ac9 Mon Sep 17 00:00:00 2001 From: safishamsi Date: Sat, 10 Oct 2026 21:20:29 +0100 Subject: [PATCH] fix(html): stop a node label from breaking out of the embedded script block (#4124) Node data is embedded as JSON inside a no longer closed the tag and graph.html rendered blank. Escape every `<` as < in both exporters/html.py and tree_html.py; labels still render because `<` round-trips through JSON.parse. Co-Authored-By: Claude Opus 4.8 --- graphify/exporters/html.py | 8 +++- graphify/tree_html.py | 7 +-- tests/test_html_script_breakout.py | 71 ++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 tests/test_html_script_breakout.py diff --git a/graphify/exporters/html.py b/graphify/exporters/html.py index 14f781249..1fbe8eb10 100644 --- a/graphify/exporters/html.py +++ b/graphify/exporters/html.py @@ -613,9 +613,13 @@ def to_html( n = member_counts.get(cid, len(communities.get(cid, []))) if member_counts else len(communities.get(cid, [])) legend_data.append({"cid": cid, "color": color, "label": lbl, "count": n}) - # Escape sequences so embedded JSON cannot break out of the script tag + # Escape every `<` as < so embedded JSON cannot break out of the ` no longer closes the tag and the page goes + # blank (#4124). `<` round-trips through JSON.parse, so labels render unchanged. def _js_safe(obj) -> str: - return json.dumps(obj).replace(" str: - # Escape sequences so embedded JSON cannot break out of the - #