[ticket/10824] Switch to new namespace for json sanitizer

PHPBB3-10824
This commit is contained in:
Marc Alexander 2020-01-20 20:09:10 +01:00
parent 27c69c2740
commit 93949d1be4
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
6 changed files with 26 additions and 25 deletions

View file

@ -1203,7 +1203,7 @@ class acp_styles
} }
$json = file_get_contents($this->styles_path . $dir . '/composer.json'); $json = file_get_contents($this->styles_path . $dir . '/composer.json');
$style_data = \phpbb\json_sanitizer::decode($json); $style_data = \phpbb\json\sanitizer::decode($json);
if (!is_array($style_data) || !isset($style_data['type']) || $style_data['type'] !== 'phpbb-style') if (!is_array($style_data) || !isset($style_data['type']) || $style_data['type'] !== 'phpbb-style')
{ {

View file

@ -13,7 +13,7 @@
namespace phpbb\cache; namespace phpbb\cache;
use phpbb\json_sanitizer; use phpbb\json\sanitizer;
/** /**
* Class for grabbing/handling cached entries * Class for grabbing/handling cached entries
@ -357,7 +357,7 @@ class service
{ {
// Re-parse cfg file // Re-parse cfg file
$json = file_get_contents($filename); $json = file_get_contents($filename);
$parsed_array = json_sanitizer::decode($json); $parsed_array = sanitizer::decode($json);
$parsed_array['filetime'] = @filemtime($filename); $parsed_array['filetime'] = @filemtime($filename);
$this->driver->put('_cfg_' . $style['style_path'], $parsed_array); $this->driver->put('_cfg_' . $style['style_path'], $parsed_array);

View file

@ -13,7 +13,7 @@
namespace phpbb\db\migration\data\v310; namespace phpbb\db\migration\data\v310;
use phpbb\json_sanitizer; use phpbb\json\sanitizer;
class style_update_p1 extends \phpbb\db\migration\migration class style_update_p1 extends \phpbb\db\migration\migration
{ {
@ -85,7 +85,7 @@ class style_update_p1 extends \phpbb\db\migration\migration
else if (file_exists($fileinfo->getPathname() . '/composer.json')) else if (file_exists($fileinfo->getPathname() . '/composer.json'))
{ {
$json = file_get_contents($fileinfo->getPathname() . '/composer.json'); $json = file_get_contents($fileinfo->getPathname() . '/composer.json');
$style_data = json_sanitizer::decode($json); $style_data = sanitizer::decode($json);
if (isset($style_data['extra']['phpbb-version']) && version_compare($style_data['extra']['phpbb-version'], '3.3.0-dev', '>=')) if (isset($style_data['extra']['phpbb-version']) && version_compare($style_data['extra']['phpbb-version'], '3.3.0-dev', '>='))
{ {
// 3.3 style // 3.3 style

View file

@ -1,24 +1,25 @@
<?php <?php
declare(strict_types=1);
/** /**
* *
* This file is part of the phpBB Forum Software package. * This file is part of the phpBB Forum Software package.
* *
* @copyright (c) phpBB Limited <https://www.phpbb.com> * @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0) * @license GNU General Public License, version 2 (GPL-2.0)
* *
* For full copyright and license information, please see * For full copyright and license information, please see
* the docs/CREDITS.txt file. * the docs/CREDITS.txt file.
* *
*/ */
namespace phpbb; namespace phpbb\json;
use phpbb\request\type_cast_helper; use phpbb\request\type_cast_helper;
/** /**
* JSON sanitizer class * JSON sanitizer class
*/ */
class json_sanitizer class sanitizer
{ {
/** /**
* Sanitize json data * Sanitize json data
@ -27,7 +28,7 @@ class json_sanitizer
* *
* @return array Sanitized data * @return array Sanitized data
*/ */
static public function sanitize($data) static public function sanitize(array $data) : array
{ {
if (!empty($data)) if (!empty($data))
{ {
@ -48,7 +49,7 @@ class json_sanitizer
* *
* @return array Data array * @return array Data array
*/ */
static public function decode($json) static public function decode(string $json) : array
{ {
$data = json_decode($json, true); $data = json_decode($json, true);
return !empty($data) ? self::sanitize($data) : []; return !empty($data) ? self::sanitize($data) : [];

View file

@ -13,7 +13,7 @@
namespace phpbb\language; namespace phpbb\language;
use phpbb\json_sanitizer; use phpbb\json\sanitizer;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
/** /**
@ -55,7 +55,7 @@ class language_file_helper
foreach ($finder as $file) foreach ($finder as $file)
{ {
$json = $file->getContents(); $json = $file->getContents();
$data = json_sanitizer::decode($json); $data = sanitizer::decode($json);
$available_languages[] = $this->get_language_data_from_json($data); $available_languages[] = $this->get_language_data_from_json($data);
} }
@ -72,7 +72,7 @@ class language_file_helper
public function get_language_data_from_composer_file($path) public function get_language_data_from_composer_file($path)
{ {
$json_data = file_get_contents($path); $json_data = file_get_contents($path);
return $this->get_language_data_from_json(json_sanitizer::decode($json_data)); return $this->get_language_data_from_json(sanitizer::decode($json_data));
} }
/** /**

View file

@ -390,7 +390,7 @@ class version_helper
} }
// Sanitize any data we retrieve from a server // Sanitize any data we retrieve from a server
$info = json_sanitizer::decode($info); $info = json\sanitizer::decode($info);
if (empty($info['stable']) && empty($info['unstable'])) if (empty($info['stable']) && empty($info['unstable']))
{ {