From 2f17b522a523c28a70904bfdc962e04f0f4cebf5 Mon Sep 17 00:00:00 2001 From: "Nicholas K. Dionysopoulos" Date: Tue, 16 Jun 2015 12:20:13 +0300 Subject: [PATCH] UTF-8 Multibyte (utf8mb4) support Fixed a problem with JFilterInput and arrays. --- libraries/joomla/filter/input.php | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/libraries/joomla/filter/input.php b/libraries/joomla/filter/input.php index 02bb2f5e79c68..67545ccf70f0c 100644 --- a/libraries/joomla/filter/input.php +++ b/libraries/joomla/filter/input.php @@ -231,7 +231,7 @@ public function clean($source, $type = 'string') if ($this->stripUSC) { // Alternatively: preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xE2\xAF\x91", $source) but it'd be slower. - $source = preg_replace('/[\xF0-\xF7].../s', "\xE2\xAF\x91", $source); + $source = $this->stripUSC($source); } // Handle the type constraint @@ -1128,4 +1128,34 @@ protected function _stripCSSExpressions($source) return $return; } + + /** + * + * Recursively strip Unicode Supplementary Characters from the source. Not: objects cannot be filtered. + * + * @param mixed $source The data to filter + * + * @return mixed The filtered result + */ + protected function stripUSC($source) + { + if (is_object($source)) + { + return $source; + } + + if (is_array($source)) + { + $filteredArray = array(); + + foreach ($source as $k => $v) + { + $filteredArray[$k] = $this->stripUSC($v); + } + + return $filteredArray; + } + + return preg_replace('/[\xF0-\xF7].../s', "\xE2\xAF\x91", $source); + } }