From: Hypolite Petovan Date: Mon, 19 Dec 2022 15:22:05 +0000 (-0500) Subject: Add logging and default value when JSON encode->decode fails in JsonLD::compact X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f2188835e79fc850fd4ae56083cc78092cbf4f00;p=friendica.git Add logging and default value when JSON encode->decode fails in JsonLD::compact - Address part of https://github.com/friendica/friendica/issues/12011#issuecomment-1357768936 --- diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index 25ce74fcc7..51d15cb10a 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -140,7 +140,7 @@ class JsonLD * @return array Compacted JSON array * @throws Exception */ - public static function compact($json, bool $logfailed = true) + public static function compact($json, bool $logfailed = true): array { jsonld_set_document_loader('Friendica\Util\JsonLD::documentLoader'); @@ -203,6 +203,11 @@ class JsonLD $json = json_decode(json_encode($compacted, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), true); + if ($json === false) { + Logger::notice('JSON encode->decode failed', ['orig_json' => $orig_json, 'compacted' => $compacted]); + $json = []; + } + return $json; }