From f2188835e79fc850fd4ae56083cc78092cbf4f00 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 19 Dec 2022 10:22:05 -0500 Subject: [PATCH] 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 --- src/Util/JsonLD.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index 25ce74fcc..51d15cb10 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; }