Milhaud commited on
Commit
fc0164d
·
1 Parent(s): e1e1f64

fix: decomposed structure preview

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -222,16 +222,18 @@ def create_error_html(message: str) -> str:
222
 
223
 
224
  def create_svg_viewer_html(svg_content: str) -> str:
225
- """Create SVG viewer HTML with XSS protection."""
226
- # Basic sanitization - in production, use a proper SVG sanitizer
227
- safe_svg = html.escape(svg_content).replace('&lt;', '<').replace('&gt;', '>')
 
 
228
 
229
  return f"""
230
  <div style='padding: 20px; background: #fff; border: 1px solid #eee; border-radius: 8px; display: block;'>
231
  <div style='display: block; align-items: center; margin-bottom: 10px;'>
232
  </div>
233
- <div id='animation-container' style='min-height: 300px; display: block; justify-content: center; align-items: center; background: #fafafa; border-radius: 4px; padding: 20px;'>
234
- {safe_svg}
235
  </div>
236
  </div>
237
  """
@@ -320,8 +322,8 @@ def create_animation_preview(animation_desc: str, svg_content: str) -> tuple:
320
  f.write(html_content)
321
  print(f"Animation preview saved to: {html_path}")
322
 
323
- # Create iframe HTML with XSS protection
324
- safe_html_content = html.escape(html_content).replace('"', '&quot;')
325
  preview_html = f"""
326
  <div style='padding: 20px; background: #fff; border: 1px solid #eee; border-radius: 8px; display: block;'>
327
  <div style='display: block; align-items: center; margin-bottom: 10px;'>
 
222
 
223
 
224
  def create_svg_viewer_html(svg_content: str) -> str:
225
+ """Create SVG viewer HTML."""
226
+ # Basic SVG validation - ensure it starts with <svg and ends with </svg>
227
+ svg_content = svg_content.strip()
228
+ if not svg_content.startswith('<svg') or not svg_content.endswith('</svg>'):
229
+ return create_error_html("Invalid SVG format")
230
 
231
  return f"""
232
  <div style='padding: 20px; background: #fff; border: 1px solid #eee; border-radius: 8px; display: block;'>
233
  <div style='display: block; align-items: center; margin-bottom: 10px;'>
234
  </div>
235
+ <div id='animation-container' style='min-height: 300px; display: flex; justify-content: center; align-items: center; background: #fafafa; border-radius: 4px; padding: 20px;'>
236
+ {svg_content}
237
  </div>
238
  </div>
239
  """
 
322
  f.write(html_content)
323
  print(f"Animation preview saved to: {html_path}")
324
 
325
+ # Create iframe HTML - only escape quotes for srcdoc attribute
326
+ safe_html_content = html_content.replace('"', '&quot;')
327
  preview_html = f"""
328
  <div style='padding: 20px; background: #fff; border: 1px solid #eee; border-radius: 8px; display: block;'>
329
  <div style='display: block; align-items: center; margin-bottom: 10px;'>