From 5dc2e500f5d93ef5da6a5f8e965c0b5f9947d22b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 28 Dec 2018 10:59:54 +0100 Subject: [PATCH] [ticket/10824] Add new helper function for decoding and sanitizing in place PHPBB3-10824 --- phpBB/phpbb/json_sanitizer.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/json_sanitizer.php b/phpBB/phpbb/json_sanitizer.php index 1a1d8aef3a..157502624f 100644 --- a/phpBB/phpbb/json_sanitizer.php +++ b/phpBB/phpbb/json_sanitizer.php @@ -13,6 +13,8 @@ namespace phpbb; +use phpbb\request\type_cast_helper; + /** * JSON sanitizer class */ @@ -30,7 +32,7 @@ class json_sanitizer if (!empty($data)) { $json_sanitizer = function (&$value, $key) { - $type_cast_helper = new \phpbb\request\type_cast_helper(); + $type_cast_helper = new type_cast_helper(); $type_cast_helper->set_var($value, $value, gettype($value), true); }; array_walk_recursive($data, $json_sanitizer); @@ -38,4 +40,16 @@ class json_sanitizer return $data; } + + /** + * Decode and sanitize json data + * + * @param string $json JSON data string + * + * @return array Data array + */ + static public function decode($json) + { + return self::sanitize(json_decode($json, true)); + } }