chg: [internal] Use JsonTool for JSON encoding

pull/7832/head
Jakub Onderka 2021-10-13 15:34:34 +02:00
parent d19c76388d
commit 481c268105
2 changed files with 25 additions and 3 deletions

View File

@ -0,0 +1,20 @@
<?php
class JsonTool
{
/**
* @param mixed $value
* @param bool $prettyPrint
* @returns string
*/
public static function encode($value, $prettyPrint = false)
{
$flags = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
if (defined('JSON_THROW_ON_ERROR')) {
$flags |= JSON_THROW_ON_ERROR; // Throw exception on error if supported
}
if ($prettyPrint) {
$flags |= JSON_PRETTY_PRINT;
}
return json_encode($value, $flags);
}
}

View File

@ -3,6 +3,7 @@ App::uses('AppModel', 'Model');
App::uses('CakeEmail', 'Network/Email');
App::uses('FileAccessTool', 'Tools');
App::uses('AttachmentTool', 'Tools');
App::uses('JsonTool', 'Tools');
App::uses('TmpFileTool', 'Tools');
App::uses('SendEmailTemplate', 'Tools');
@ -5865,6 +5866,7 @@ class Event extends AppModel
* @return int|string|array
* @throws JsonException
* @throws InvalidArgumentException
* @throws Exception
*/
public function upload_stix(array $user, $file, $stix_version, $original_file, $publish)
{
@ -5970,7 +5972,7 @@ class Event extends AppModel
}
}
}
FileAccessTool::writeToFile($synonymsToTagNames, json_encode($mapping));
FileAccessTool::writeToFile($synonymsToTagNames, JsonTool::encode($mapping));
}
return $synonymsToTagNames;
}
@ -6773,7 +6775,7 @@ class Event extends AppModel
);
try {
$filePath = FileAccessTool::writeToTempFile(json_encode($tempData));
$filePath = FileAccessTool::writeToTempFile(JsonTool::encode($tempData));
$process_id = CakeResque::enqueue(
Job::WORKER_PRIO,
'EventShell',
@ -6805,7 +6807,7 @@ class Event extends AppModel
);
try {
$filePath = FileAccessTool::writeToTempFile(json_encode($tempData));
$filePath = FileAccessTool::writeToTempFile(JsonTool::encode($tempData));
$process_id = CakeResque::enqueue(
Job::WORKER_PRIO,
'EventShell',