Spaces:
Sleeping
Sleeping
Commit
·
56292f7
1
Parent(s):
69f914e
Fix JSON truncation in HTML attributes for Top 10 predictions
Browse filesEnhanced escape_for_attr function to properly escape all special characters
that could break HTML attributes, including newlines, tabs, and quotes.
This fixes the "Unexpected end of JSON input" error in Top 10 predictions.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
visualization/html_generator.py
CHANGED
|
@@ -352,7 +352,16 @@ def generate_comparison_html(
|
|
| 352 |
html_content = []
|
| 353 |
|
| 354 |
def escape_for_attr(s):
|
| 355 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
|
| 357 |
for token in tokens:
|
| 358 |
token_text = token["text"]
|
|
|
|
| 352 |
html_content = []
|
| 353 |
|
| 354 |
def escape_for_attr(s):
|
| 355 |
+
# Escape all characters that could break HTML attributes
|
| 356 |
+
# Order matters: & must be escaped first
|
| 357 |
+
return (s.replace("&", "&")
|
| 358 |
+
.replace('"', """)
|
| 359 |
+
.replace("'", "'")
|
| 360 |
+
.replace("<", "<")
|
| 361 |
+
.replace(">", ">")
|
| 362 |
+
.replace("\n", " ")
|
| 363 |
+
.replace("\r", " ")
|
| 364 |
+
.replace("\t", "	"))
|
| 365 |
|
| 366 |
for token in tokens:
|
| 367 |
token_text = token["text"]
|