Jellyfish042 Claude Sonnet 4.5 commited on
Commit
56292f7
·
1 Parent(s): 69f914e

Fix JSON truncation in HTML attributes for Top 10 predictions

Browse files

Enhanced 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>

Files changed (1) hide show
  1. visualization/html_generator.py +10 -1
visualization/html_generator.py CHANGED
@@ -352,7 +352,16 @@ def generate_comparison_html(
352
  html_content = []
353
 
354
  def escape_for_attr(s):
355
- return s.replace("&", "&amp;").replace('"', "&quot;").replace("<", "&lt;").replace(">", "&gt;")
 
 
 
 
 
 
 
 
 
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("&", "&amp;")
358
+ .replace('"', "&quot;")
359
+ .replace("'", "&#39;")
360
+ .replace("<", "&lt;")
361
+ .replace(">", "&gt;")
362
+ .replace("\n", "&#10;")
363
+ .replace("\r", "&#13;")
364
+ .replace("\t", "&#9;"))
365
 
366
  for token in tokens:
367
  token_text = token["text"]