From ead574ba7fc18be7735b7180b2317c5af1cdc72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Wed, 6 Mar 2024 00:26:55 +0100 Subject: [PATCH] fix: Remove calls to deprecated OC_JSON::encode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit to_string was useless because L10N string is json serializable now and serialize to string correctly. Removed all external calls to OC_JSON::encode to ease removing the rest of it later. Signed-off-by: Côme Chilliet --- lib/private/legacy/OC_API.php | 2 +- lib/private/legacy/OC_EventSource.php | 4 ++-- lib/private/legacy/OC_JSON.php | 14 +------------- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/lib/private/legacy/OC_API.php b/lib/private/legacy/OC_API.php index 862e73e6edd..facd08c1d2f 100644 --- a/lib/private/legacy/OC_API.php +++ b/lib/private/legacy/OC_API.php @@ -171,7 +171,7 @@ class OC_API { ], ]; if ($format == 'json') { - return OC_JSON::encode($response); + return json_encode($response, JSON_HEX_TAG); } $writer = new XMLWriter(); diff --git a/lib/private/legacy/OC_EventSource.php b/lib/private/legacy/OC_EventSource.php index cd72ba1f2d5..49fde4a214f 100644 --- a/lib/private/legacy/OC_EventSource.php +++ b/lib/private/legacy/OC_EventSource.php @@ -113,13 +113,13 @@ class OC_EventSource implements \OCP\IEventSource { } if ($this->fallback) { $response = '' . PHP_EOL; + . $this->fallBackId . ',"' . ($type ?? '') . '",' . json_encode($data, JSON_HEX_TAG) . ')' . PHP_EOL; echo $response; } else { if ($type) { echo 'event: ' . $type . PHP_EOL; } - echo 'data: ' . OC_JSON::encode($data) . PHP_EOL; + echo 'data: ' . json_encode($data, JSON_HEX_TAG) . PHP_EOL; } echo PHP_EOL; flush(); diff --git a/lib/private/legacy/OC_JSON.php b/lib/private/legacy/OC_JSON.php index b9cfb8210e0..b6791fe4b85 100644 --- a/lib/private/legacy/OC_JSON.php +++ b/lib/private/legacy/OC_JSON.php @@ -113,23 +113,11 @@ class OC_JSON { echo self::encode($data); } - /** - * Convert OC_L10N_String to string, for use in json encodings - */ - protected static function to_string(&$value) { - if ($value instanceof \OC\L10N\L10NString) { - $value = (string)$value; - } - } - /** * Encode JSON * @deprecated Use a AppFramework JSONResponse instead */ - public static function encode($data) { - if (is_array($data)) { - array_walk_recursive($data, ['OC_JSON', 'to_string']); - } + private static function encode($data) { return json_encode($data, JSON_HEX_TAG); } }