[SPIP] v3.2.12 -> v3.2.12 - Reinstallation avec le spip_loader
[lhc/web/www.git] / www / plugins-dist / textwheel / wheels / spip / echappe-js.php
1 <?php
2
3 /**
4 * Fonctions utiles pour la wheel echappe-js
5 *
6 * @SPIP\Textwheel\Wheel\SPIP\Fonctions
7 **/
8
9 if (!defined('_ECRIRE_INC_VERSION')) {
10 return;
11 }
12
13 function echappe_anti_xss($match) {
14 static $safehtml;
15
16 if (!is_array($match) or !strlen($match[0])) {
17 return "";
18 }
19 $texte = &$match[0];
20
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)
24 ) {
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)
29 ) {
30 if (!isset($safehtml)) {
31 $safehtml = charger_fonction('safehtml', 'inc', true);
32 }
33 if (!$safehtml or strlen($safehtml($texte)) !== strlen($texte)) {
34 $texte = nl2br(htmlspecialchars($texte));
35 }
36 }
37
38 if (strpos($texte, "<") === false) {
39 $texte = "<code class=\"echappe-js\">$texte</code>";
40 }
41
42 return $texte;
43 }