4 * Fonctions utiles pour la wheel echappe-js
6 * @SPIP\Textwheel\Wheel\SPIP\Fonctions
9 if (!defined('_ECRIRE_INC_VERSION')) {
13 function echappe_anti_xss($match) {
16 if (!is_array($match) or !strlen($match[0])) {
21 // on echappe les urls data: javascript: et tout ce qui ressemble
22 if (strpos($texte, ":") !== false
23 and preg_match(",(data|script)\s*:,iS", $texte)
25 $texte = nl2br(htmlspecialchars($texte));
26 } // on echappe si on a possiblement un attribut onxxx et que ca passe pas dans safehtml
27 elseif (stripos($texte, "on") !== false
28 and preg_match(",\bon\w+\s*=,i", $texte)
30 if (!isset($safehtml)) {
31 $safehtml = charger_fonction('safehtml', 'inc', true);
33 if (!$safehtml or strlen($safehtml($texte)) !== strlen($texte)) {
34 $texte = nl2br(htmlspecialchars($texte));
38 if (strpos($texte, "<") === false) {
39 $texte = "<code class=\"echappe-js\">$texte</code>";