mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-09-25 01:53:03 +02:00
Synopsis : normalisation SÛRE des text ajouté par formulaire
- fins de ligne \r\n/\r → \n,
- blocs de lignes vides → \n\n, è
- espaces/tabulations/NBSP → espace unique,
- trim.
Les retours à la ligne simples intra-paragraphe sont LAISSÉS INTACTS :
une coupure de ligne peut être une vraie frontière de mot (→ espace)
ou une coupure du mot ("dyna\nmiques" → "dynamiques"),
indistinguables sans dictionnaire — automatiser corromprait l'entrée
("poursuivantsur").
Migration batch 045 (backfill des données existantes) RETIRÉE : le
nettoyage automatique fiable des synopsis existants est impossible.
Chaque modification est testée (277 tests PHPUnit).
This commit is contained in:
@@ -609,12 +609,39 @@ class ThesisCreateController
|
||||
// ── Private: input helpers ────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Trim and strip HTML tags from a string value.
|
||||
* htmlspecialchars is applied at render time, not here.
|
||||
* Normalise a submitted string value.
|
||||
*
|
||||
* Only the UNAMBIGUOUS cleanups are applied here. We deliberately do NOT
|
||||
* auto-collapse or rejoin single newlines inside a paragraph: a line break
|
||||
* can be either a real word boundary (should become a space) or a word split
|
||||
* across the line ("dyna\nmiques", should be rejoined to "dynamiques"),
|
||||
* and these are indistinguishable without a dictionary. Trying to guess
|
||||
* corrupts valid input (e.g. "se poursuivant\nsur" → "se poursuivantsur"),
|
||||
* so such breaks are left untouched and must be fixed by the author.
|
||||
*
|
||||
* Responsibilities:
|
||||
* - strip HTML tags (htmlspecialchars is applied at render time, not here)
|
||||
* - normalise all line endings to \n (handles \r\n and bare \r)
|
||||
* - collapse runs of horizontal whitespace (spaces, tabs, NBSP) to one space
|
||||
* - collapse multiple blank lines into a single paragraph separator (\n\n)
|
||||
* - trim leading/trailing whitespace and blank lines
|
||||
*/
|
||||
private function sanitiseString(string $input): string
|
||||
{
|
||||
return strip_tags(trim($input));
|
||||
$input = strip_tags($input);
|
||||
|
||||
// Normalise all line endings to \n (handles \r\n and bare \r).
|
||||
$input = preg_replace('/\r\n|\r|\n/', "\n", $input);
|
||||
|
||||
// Collapse multiple blank lines into a single paragraph separator.
|
||||
$input = preg_replace("/\n{2,}/u", "\n\n", $input);
|
||||
|
||||
// Collapse runs of horizontal whitespace (spaces, tabs, NBSP gaps, …)
|
||||
// into a single space. Single newlines inside a paragraph are NOT
|
||||
// touched, for the reason explained above.
|
||||
$input = preg_replace('/[ \t\x0B\x00\xC2\xA0]+/u', ' ', $input);
|
||||
|
||||
return trim($input, " \t\n\r\0\x0B\xC2\xA0");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user