fix: tojson filter must return Markup to avoid HTML-escaping quotes
All checks were successful
Deploy / deploy (push) Successful in 15s
All checks were successful
Deploy / deploy (push) Successful in 15s
Jinja2 autoescaping turns " into " after filters run unless the filter returns a Markup (safe) object. json.dumps alone produced broken JS (const REPLICA_NAME = "name";). Wrap json.dumps output in markupsafe.Markup to prevent escaping. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -129,9 +129,10 @@ def create_app() -> FastAPI:
|
|||||||
|
|
||||||
# Templates
|
# Templates
|
||||||
import json as _json
|
import json as _json
|
||||||
|
from markupsafe import Markup as _Markup
|
||||||
templates_dir = Path(__file__).parent / "templates"
|
templates_dir = Path(__file__).parent / "templates"
|
||||||
templates = Jinja2Templates(directory=str(templates_dir))
|
templates = Jinja2Templates(directory=str(templates_dir))
|
||||||
templates.env.filters["tojson"] = _json.dumps
|
templates.env.filters["tojson"] = lambda v: _Markup(_json.dumps(v))
|
||||||
|
|
||||||
# Register UI routes (must come before API to avoid catch-all conflicts)
|
# Register UI routes (must come before API to avoid catch-all conflicts)
|
||||||
from .ui.routes import router as ui_router, setup_templates
|
from .ui.routes import router as ui_router, setup_templates
|
||||||
|
|||||||
Reference in New Issue
Block a user