]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Makes escape a recursive function which handle array of strings
authorArthurHoaro <arthur@hoa.ro>
Sun, 20 Mar 2016 13:14:38 +0000 (14:14 +0100)
committerArthurHoaro <arthur@hoa.ro>
Fri, 25 Mar 2016 18:17:59 +0000 (19:17 +0100)
application/Utils.php

index bcf5bdb58130efae179a9879e2bf6660ce51d226..5b8ca508576a94b0bafd0a6ee957a99fd3a7588e 100644 (file)
@@ -63,14 +63,22 @@ function endsWith($haystack, $needle, $case=true)
 
 /**
  * Htmlspecialchars wrapper
+ * Support multidimensional array of strings.
  *
- * @param string $str the string to escape.
+ * @param mixed $input Data to escape: a single string or an array of strings.
  *
  * @return string escaped.
  */
-function escape($str)
+function escape($input)
 {
-    return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false);
+    if (is_array($input)) {
+        $out = array();
+        foreach($input as $key => $value) {
+            $out[$key] = escape($value);
+        }
+        return $out;
+    }
+    return htmlspecialchars($input, ENT_COMPAT, 'UTF-8', false);
 }
 
 /**