Add FORK_JSON_ENCODE constant
This commit is contained in:
parent
61c613123a
commit
5ce8e20f9b
12 changed files with 19 additions and 29 deletions
app
|
@ -21,8 +21,6 @@ use Throwable;
|
|||
|
||||
class Log implements LoggerInterface
|
||||
{
|
||||
const JSON_OPTIONS = \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_INVALID_UTF8_SUBSTITUTE | \JSON_THROW_ON_ERROR;
|
||||
|
||||
protected string $path;
|
||||
protected string $lineFormat;
|
||||
protected string $timeFormat;
|
||||
|
@ -201,7 +199,7 @@ class Log implements LoggerInterface
|
|||
'%datetime%' => $dt->format($this->timeFormat),
|
||||
'%level_name%' => $level,
|
||||
'%message%' => \addcslashes($message, "\0..\37\\"),
|
||||
'%context%' => \json_encode($context, self::JSON_OPTIONS),
|
||||
'%context%' => \json_encode($context, FORK_JSON_ENCODE | \JSON_INVALID_UTF8_SUBSTITUTE),
|
||||
];
|
||||
|
||||
return \strtr($this->lineFormat, $result);
|
||||
|
|
|
@ -20,8 +20,6 @@ class Structure extends Model
|
|||
const TAG_PATTERN = '%^(?:ROOT|[a-z\*][a-z\d-]{0,10})$%D';
|
||||
const ATTR_PATTERN = '%^[a-z-]{2,15}$%D';
|
||||
|
||||
const JSON_OPTIONS = \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR;
|
||||
|
||||
/**
|
||||
* Ключ модели для контейнера
|
||||
*/
|
||||
|
@ -139,7 +137,7 @@ class Structure extends Model
|
|||
$a['text_handler'] = $this->text_handler;
|
||||
}
|
||||
|
||||
return \json_encode($a, self::JSON_OPTIONS);
|
||||
return \json_encode($a, FORK_JSON_ENCODE);
|
||||
}
|
||||
|
||||
protected function gettype(): string
|
||||
|
|
|
@ -33,7 +33,7 @@ class Save extends Method
|
|||
if (\array_key_exists($name, $values)) {
|
||||
switch ($name[0]) {
|
||||
case 'a':
|
||||
$value = \json_encode($values[$name], \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR);
|
||||
$value = \json_encode($values[$name], FORK_JSON_ENCODE);
|
||||
|
||||
break;
|
||||
case 'b':
|
||||
|
|
|
@ -463,7 +463,7 @@ class Forum extends DataModel
|
|||
|
||||
$data['moderators'] = empty($data['moderators']) || ! \is_array($data['moderators'])
|
||||
? ''
|
||||
: \json_encode($data['moderators']);
|
||||
: \json_encode($data['moderators'], FORK_JSON_ENCODE);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ class Refresh extends Action
|
|||
*/
|
||||
protected function formatModers(string $str): ?array
|
||||
{
|
||||
$moderators = \json_decode($str, true);
|
||||
$moderators = \json_decode($str, true, 512, \JSON_THROW_ON_ERROR);
|
||||
|
||||
return $moderators ?: null;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class Bans extends Admin
|
|||
{
|
||||
unset($data['token']);
|
||||
|
||||
$data = \base64_encode(\json_encode($data));
|
||||
$data = \base64_encode(\json_encode($data, FORK_JSON_ENCODE));
|
||||
$hash = $this->c->Secury->hash($data);
|
||||
|
||||
return "{$data}:{$hash}";
|
||||
|
@ -57,7 +57,7 @@ class Bans extends Admin
|
|||
|
||||
if (
|
||||
! \hash_equals($data[1], $this->c->Secury->hash($data[0]))
|
||||
|| ! \is_array($data = \json_decode(\base64_decode($data[0], true), true))
|
||||
|| ! \is_array($data = \json_decode(\base64_decode($data[0], true), true, 512, \JSON_THROW_ON_ERROR))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -25,8 +25,6 @@ class Install extends Admin
|
|||
const SQLITE_MIN = '3.25.0';
|
||||
const PGSQL_MIN = '10.0';
|
||||
|
||||
const JSON_OPTIONS = \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR;
|
||||
|
||||
/**
|
||||
* Для MySQL
|
||||
*/
|
||||
|
@ -1503,11 +1501,11 @@ class Install extends Admin
|
|||
'i_poll_time' => 60,
|
||||
'i_poll_term' => 3,
|
||||
'b_poll_guest' => 0,
|
||||
'a_max_users' => \json_encode(['number' => 1, 'time' => \time()], self::JSON_OPTIONS),
|
||||
'a_bb_white_mes' => \json_encode([], self::JSON_OPTIONS),
|
||||
'a_bb_white_sig' => \json_encode(['b', 'i', 'u', 'color', 'colour', 'email', 'url'], self::JSON_OPTIONS),
|
||||
'a_bb_black_mes' => \json_encode([], self::JSON_OPTIONS),
|
||||
'a_bb_black_sig' => \json_encode([], self::JSON_OPTIONS),
|
||||
'a_max_users' => \json_encode(['number' => 1, 'time' => \time()], FORK_JSON_ENCODE),
|
||||
'a_bb_white_mes' => \json_encode([], FORK_JSON_ENCODE),
|
||||
'a_bb_white_sig' => \json_encode(['b', 'i', 'u', 'color', 'colour', 'email', 'url'], FORK_JSON_ENCODE),
|
||||
'a_bb_black_mes' => \json_encode([], FORK_JSON_ENCODE),
|
||||
'a_bb_black_sig' => \json_encode([], FORK_JSON_ENCODE),
|
||||
'a_guest_set' => \json_encode(
|
||||
[
|
||||
'show_smilies' => 1,
|
||||
|
@ -1515,7 +1513,7 @@ class Install extends Admin
|
|||
'show_avatars' => 1,
|
||||
'show_img' => 1,
|
||||
'show_img_sig' => 1,
|
||||
], self::JSON_OPTIONS
|
||||
], FORK_JSON_ENCODE
|
||||
),
|
||||
's_РЕГИСТР' => 'Ok',
|
||||
];
|
||||
|
@ -1585,7 +1583,7 @@ class Install extends Admin
|
|||
foreach ($bbcodes as $bbcode) {
|
||||
$vars = [
|
||||
':tag' => $bbcode['tag'],
|
||||
':structure' => \json_encode($bbcode, self::JSON_OPTIONS),
|
||||
':structure' => \json_encode($bbcode, FORK_JSON_ENCODE),
|
||||
];
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
|
|
|
@ -28,7 +28,6 @@ class Update extends Admin
|
|||
const LATEST_REV_WITH_DB_CHANGES = 55;
|
||||
const LOCK_NAME = 'lock_update';
|
||||
const LOCK_TTL = 1800;
|
||||
const JSON_OPTIONS = \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR;
|
||||
const CONFIG_FILE = 'main.php';
|
||||
|
||||
protected string $configFile;
|
||||
|
|
|
@ -39,7 +39,7 @@ abstract class Users extends Admin
|
|||
if (\is_array($data)) {
|
||||
unset($data['token']);
|
||||
|
||||
$data = \base64_encode(\json_encode($data));
|
||||
$data = \base64_encode(\json_encode($data, FORK_JSON_ENCODE));
|
||||
$hash = $this->c->Secury->hash($data);
|
||||
|
||||
return "{$data}:{$hash}";
|
||||
|
@ -67,7 +67,7 @@ abstract class Users extends Admin
|
|||
|
||||
if (
|
||||
! \hash_equals($data[1], $this->c->Secury->hash($data[0]))
|
||||
|| ! \is_array($data = \json_decode(\base64_decode($data[0], true), true))
|
||||
|| ! \is_array($data = \json_decode(\base64_decode($data[0], true), true, 512, \JSON_THROW_ON_ERROR))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@ use function \ForkBB\__;
|
|||
|
||||
class Poll extends DataModel
|
||||
{
|
||||
const JSON_OPTIONS = \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR;
|
||||
|
||||
/**
|
||||
* Ключ модели для контейнера
|
||||
*/
|
||||
|
@ -303,7 +301,7 @@ class Poll extends DataModel
|
|||
$vars = [
|
||||
':tid' => $this->tid,
|
||||
':uid' => $this->c->user->id,
|
||||
':rez' => \json_encode($data, self::JSON_OPTIONS),
|
||||
':rez' => \json_encode($data, FORK_JSON_ENCODE),
|
||||
];
|
||||
$query = 'INSERT INTO ::poll_voted (tid, uid, rez)
|
||||
VALUES (?i:tid, ?i:uid, ?s:rez)';
|
||||
|
|
|
@ -17,8 +17,6 @@ use RuntimeException;
|
|||
|
||||
abstract class Driver extends Model
|
||||
{
|
||||
const JSON_OPTIONS = \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR;
|
||||
|
||||
/**
|
||||
* Ключ модели для контейнера
|
||||
*/
|
||||
|
@ -226,7 +224,7 @@ abstract class Driver extends Model
|
|||
|
||||
} elseif (\is_string($result)) {
|
||||
if (\str_starts_with($this->respContentType, 'application/json')) {
|
||||
$data = \json_decode($result, true, 20, self::JSON_OPTIONS);
|
||||
$data = \json_decode($result, true, 20, \JSON_THROW_ON_ERROR);
|
||||
|
||||
if (\is_array($data)) {
|
||||
return $this->c->Secury->replInvalidChars($data);
|
||||
|
|
|
@ -41,6 +41,7 @@ define('FORK_GEN_NOT', 0);
|
|||
define('FORK_GEN_MAN', 1);
|
||||
define('FORK_GEN_FEM', 2);
|
||||
|
||||
define('FORK_JSON_ENCODE', \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR);
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue