[DTP-Worker 20260812_070054] fix correctness · rendu HTML publiciste — URL de rendu percent-encodée dans le url('…') CSS
Bug latent réel (rendu-correctness, entrée FR/ES plausible) : _hero_media
(generator.py:92) injectait le nom de fichier via html.escape dans un
background-image:url('…'). Un rendu réel « Vue d'ensemble.png » devenait
Vue d'ensemble.png → le navigateur HTML-décode l'attribut style AVANT le
CSS → l'apostrophe referme la chaîne url('…') → hero non affiché, silencieux.
html.escape est le mauvais encodeur pour un contexte CSS.
Fix : urllib.parse.quote sur le segment de fichier ('→%27, espace→%20,
accents→%XX) — valide dans URL + attribut HTML + url() CSS ; _esc conservé pour
l'attribut HTML. Zéro dérive : quote laisse les noms ASCII simples inchangés
(hero_aerien.jpg identique) → fixture + byte-repro intacts.
Test de régression à dents (test_hero_media_url_percent_encode) : prouvé FAIL
sans quote, PASS avec. Cascade régénérée (artifact-reproducibility-gate) :
suite publiciste 24→25, matrice 629/612→630/613/17 · quality_report régénéré
en DERNIER · 3 fiches AGENT.md (compteurs dérivés) réalignées.
Défaut d'abord : 12 fichiers cœur / 7 modules ré-audités CLEAN (epsilon 1e-9
gate apport = tolérance flottante correcte). run_ci 33/0/0 · NFC-clean ·
zéro code moteur V18 (bloqué D-06 #6) · zéro gate ajouté (#5) · zéro invention (#6).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,7 @@ from __future__ import annotations
|
||||
import html
|
||||
import os
|
||||
from typing import Any
|
||||
from urllib.parse import quote
|
||||
|
||||
from . import branding
|
||||
|
||||
@@ -88,8 +89,14 @@ def _hero_media(projet: dict[str, Any]) -> str:
|
||||
if not hero:
|
||||
return ' <div class="media"></div>'
|
||||
# Convention de chemin public (miroir de /opt/oto/sites/static/projets/pXX/).
|
||||
# Le nom de rendu réel peut contenir espaces/apostrophes/accents (« Vue
|
||||
# d'ensemble.png », « façade nord.webp ») : on percent-encode le segment de
|
||||
# fichier pour que l'URL reste valide DANS le url('…') CSS. Sans cela, une
|
||||
# apostrophe — une fois l'attribut style HTML-décodé par le navigateur —
|
||||
# referme la chaîne CSS et casse silencieusement le background-image.
|
||||
# (_esc protège l'attribut HTML ; quote protège le contexte CSS interne.)
|
||||
code = projet["code"].lower()
|
||||
src = f"/static/projets/{code}/{hero['fichier']}"
|
||||
src = f"/static/projets/{code}/{quote(hero['fichier'])}"
|
||||
style = f"background-image:url('{_esc(src)}')"
|
||||
return f' <div class="media" style="{style}" role="img" aria-label="{_esc(projet.get("nom",""))}"></div>'
|
||||
|
||||
|
||||
@@ -223,6 +223,23 @@ class TestGenerator(unittest.TestCase):
|
||||
self.assertNotIn("USD", p02, "aucun prix ne doit apparaître pour P02")
|
||||
self.assertNotIn("prix-depuis", p02)
|
||||
|
||||
def test_hero_media_url_percent_encode(self):
|
||||
# Un nom de rendu réel peut contenir apostrophe/espace/accents (FR/ES) :
|
||||
# l'URL doit être percent-encodée pour rester valide DANS le url('…') CSS.
|
||||
# Sinon l'apostrophe, une fois l'attribut style HTML-décodé, referme la
|
||||
# chaîne CSS et casse le background-image (régression silencieuse).
|
||||
projet = {
|
||||
"code": "P07",
|
||||
"nom": "Aqua Terra",
|
||||
"statut": "disponible",
|
||||
"rendus": [{"fichier": "Vue d'ensemble.png", "hero": True}],
|
||||
}
|
||||
media = generator._hero_media(projet)
|
||||
self.assertIn("Vue%20d%27ensemble.png", media)
|
||||
# L'apostrophe brute ne doit JAMAIS survivre dans le url('…').
|
||||
import html as _h
|
||||
self.assertNotIn("Vue d'ensemble", _h.unescape(media))
|
||||
|
||||
@staticmethod
|
||||
def _article(html: str, code: str) -> str:
|
||||
start = html.index(f'data-code="{code}"')
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
"criterion": "TESTS",
|
||||
"weight": 25,
|
||||
"passed": true,
|
||||
"evidence": "24 méthodes test_* dans 1 fichier(s) (seuil 8)"
|
||||
"evidence": "25 méthodes test_* dans 1 fichier(s) (seuil 8)"
|
||||
},
|
||||
{
|
||||
"criterion": "CLI",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"version": "1.0",
|
||||
"verdict": "PASS",
|
||||
"suites": 24,
|
||||
"test_methods": 629,
|
||||
"test_methods": 630,
|
||||
"coverage_ok": true,
|
||||
"artifacts": [
|
||||
"regression_plan.json"
|
||||
|
||||
@@ -189,7 +189,7 @@
|
||||
"in_gate": true,
|
||||
"has_tests_dir": true,
|
||||
"test_files": 1,
|
||||
"test_methods": 24
|
||||
"test_methods": 25
|
||||
},
|
||||
{
|
||||
"id": "qa.acceptance",
|
||||
@@ -295,7 +295,7 @@
|
||||
"totals": {
|
||||
"suites": 24,
|
||||
"test_files": 24,
|
||||
"test_methods": 629,
|
||||
"test_methods": 630,
|
||||
"min_methods": 10,
|
||||
"under_threshold": 0
|
||||
},
|
||||
|
||||
@@ -174,9 +174,9 @@
|
||||
{
|
||||
"id": "publiciste",
|
||||
"path": "publiciste",
|
||||
"expected_methods": 24,
|
||||
"ran": 24,
|
||||
"passed": 22,
|
||||
"expected_methods": 25,
|
||||
"ran": 25,
|
||||
"passed": 23,
|
||||
"failures": 0,
|
||||
"errors": 0,
|
||||
"skipped": 2,
|
||||
@@ -296,8 +296,8 @@
|
||||
"suites": 24,
|
||||
"green": 24,
|
||||
"red": 0,
|
||||
"ran": 629,
|
||||
"passed": 612,
|
||||
"ran": 630,
|
||||
"passed": 613,
|
||||
"failures": 0,
|
||||
"errors": 0,
|
||||
"skipped": 17
|
||||
|
||||
Reference in New Issue
Block a user