[spip-check] Correction du bug de détection de code inattendu dans (…)

technova69/spip-check

Par gilles, le 29 août 2026 à 08h53min :

Correction du bug de détection de code inattendu dans les fichiers de langue

Cause confirmée

PhpAnalyzer::isLanguageFile() exigeait que le return […] (ou $GLOBALS[$GLOBALS[‹ idx_lang ›]] = […]) soit la toute première instruction. Le garde
standard if (!defined(« _ECRIRE_INC_VERSION »)) { return; } rendait le premier token T_IF → échec → invalid_language_file (critique).

Correctif

src/SpipCheck.php :

  • Nouveau helper privé withoutDirectAccessGuard() qui retire, et uniquement dans sa forme exacte, le garde canonique SPIP en préambule :
  • if (!defined(‹ _ECRIRE_INC_VERSION ›)) return;
  • if (!defined(‹ _ECRIRE_INC_VERSION ›)) { return; }
  • guillemets simples ou doubles tolérés
  • isLanguageFile() applique ensuite les vérifications existantes (retour de tableau littéral ou affectation $GLOBALS[$GLOBALS[‹ idx_lang ›]]) sur les tokens
    débarrassés du garde.
  • Toute autre instruction avant le tableau (define(…), condition arbitraire, garde sur une autre constante, function, class, marqueur webshell…) reste
    refusée.

Tests (TDD, vus échouer puis passer)

  • tests/unit/PhpAnalyzerTest.php : 3 cas acceptés (guarded return, guarded return without braces, guarded historical global) + 3 cas de non-régression
    refusés (guard with a side effect, arbitrary condition before the array, guard on an unrelated constant).
  • tests/unit/VerificationPipelineTest.php : testAcceptsALanguageFileGuardedAgainstDirectAccess reproduit exactement le scénario
    squelettes/lang/local_fr.php.

Suite complète : 204 tests unitaires + 2 d’intégration OK, ecs propre sur les fichiers modifiés, php -l OK.
Vérifié en direct sur les vrais fichiers : squelettes/lang/local_fr.php, squelettes/lang/monperso_fr.php (et
plugins/linkedin_post/lang/linkedin_post_fr.php) → accept.

Build

  • composer.json : 1.2.1 → 1.2.2, entrée CHANGELOG.md.
  • composer build régénéré → spip-check.php mono-fichier contient le correctif (return ‹ 1.2.2 ›).

Modifié
CHANGELOG.md
composer.json
spip-check.php
src/SpipCheck.php
tests/unit/PhpAnalyzerTest.php
tests/unit/VerificationPipelineTest.php

Détails : https://git.spip.net/technova69/spip-check/-/commit/89c171c0c139dc8f6b28254b6e16b3983247986d