fix: Alpine.js JSON parsing error in x-data HTML attributes

Add tojson_attr Jinja2 filter that escapes double quotes to "
for safe embedding in HTML attributes. The browser decodes entities
before Alpine.js evaluates, so JSON parses correctly.

Replaces |tojson with |tojson_attr in x-data attributes (select_recipe,
recipe_list, base flash messages). Script tag usages are unaffected.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Adriano
2026-02-07 19:31:49 +01:00
parent 6d5660b20d
commit 004f794c75
4 changed files with 23 additions and 3 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
{% block content %}
<div class="container mx-auto px-4 sm:px-6 lg:px-8 py-8 max-w-7xl"
x-data="{
recipes: {{ recipes|tojson }},
recipes: {{ recipes|tojson_attr }},
search: '{{ auto_recipe_code }}',
lot_number: '{{ auto_lot }}',
serial_number: '{{ auto_serial }}',