fix(aep-15a): ce que le public écrit et relit hors des fiches (checkpoint)
POST /api/organisations et POST /api/avis : limite de débit, seuls les
champs que pages/ajouter.vue envoie, contrôlés en type et longueur (bornes
de /api/submit pour nom), statut imposé pending (moderation_status,
ai_processed false), toute autre clé ignorée, réponse réduite à { Id }.
GET /api/comment/[orgId] et /api/avis/[orgId] : numéro strict, lignes
publiées seulement, champs affichés seulement (jamais auteur_email).
url d'une fiche publique : rendue seulement en http(s).
Test : scripts/test-fiche-publique.mjs, 189 cas (CRLF toléré).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+21
-2
@@ -67,10 +67,29 @@ export function estFichePublique(ligne: unknown): ligne is Record<string, unknow
|
||||
return !!ligne && typeof ligne === 'object' && (ligne as Record<string, unknown>).moderation_status === 'approved'
|
||||
}
|
||||
|
||||
/** La ligne réduite aux champs publics (les champs absents restent absents). */
|
||||
/** Vrai si la valeur est un lien http: ou https: (FicheDetail le rend cliquable). */
|
||||
export function estLienHttp(v: unknown): v is string {
|
||||
if (typeof v !== 'string') return false
|
||||
try {
|
||||
const u = new URL(v.trim())
|
||||
return u.protocol === 'http:' || u.protocol === 'https:'
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* La ligne réduite aux champs publics (les champs absents restent absents).
|
||||
* `url` ne sort que s'il est en http(s) : le formulaire détaillé accepte `javascript:` ou `mailto:`
|
||||
* (z.string().url()) et FicheDetail en fait un lien cliquable. `null` reste `null` (pas de lien).
|
||||
*/
|
||||
export function projeterFiche(ligne: Record<string, unknown>): Partial<Record<ChampPublicFiche, unknown>> {
|
||||
const out: Record<string, unknown> = {}
|
||||
for (const k of CHAMPS_PUBLICS_FICHE) if (Object.prototype.hasOwnProperty.call(ligne, k)) out[k] = ligne[k]
|
||||
for (const k of CHAMPS_PUBLICS_FICHE) {
|
||||
if (!Object.prototype.hasOwnProperty.call(ligne, k)) continue
|
||||
if (k === 'url' && ligne.url != null && !estLienHttp(ligne.url)) continue
|
||||
out[k] = ligne[k]
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user