From 6e284b0c0c0474f04dc0a33a7d56e9a784d5e8a3 Mon Sep 17 00:00:00 2001 From: AdrianoDev Date: Sun, 26 Apr 2026 12:32:32 +0200 Subject: [PATCH] fix(admin): apostrophe-in-translation broke /admin/stations Alpine bindings Two error messages on /admin/stations rendered Italian translations that contain an apostrophe inside a single-quoted JS literal: alert(result.detail || '{{ _("Errore nell\'eliminazione") }}'); Jinja outputs the apostrophe verbatim, so the JS string closed prematurely: alert(result.detail || 'Errore nell'eliminazione'); That syntax error blew up the entire (i.e. without `src=`) so we don't try +# to syntax-check Alpine.js / Plotly bundles served from a CDN. +_INLINE_SCRIPT_RX = re.compile( + r"]*\bsrc=)[^>]*>(.*?)", + re.DOTALL | re.IGNORECASE, +) + + +def _node_check(script: str, label: str) -> None: + """Fail the test if `node --check` rejects `script`.""" + if not script.strip(): + return + node = shutil.which("node") + if node is None: + pytest.skip("node binary not found on PATH; cannot validate JS syntax") + + fd, path = tempfile.mkstemp(suffix=".js") + try: + with os.fdopen(fd, "w", encoding="utf-8") as f: + f.write(script) + result = subprocess.run( + [node, "--check", path], + capture_output=True, + text=True, + timeout=10, + ) + finally: + os.unlink(path) + + if result.returncode != 0: + snippet = script.strip() + if len(snippet) > 600: + snippet = snippet[:600] + "\n…(truncated)…" + pytest.fail( + f"{label}: node rejected the inline