From 746c755d14582f389dc13da31d41416ca9790ea1 Mon Sep 17 00:00:00 2001 From: Ayesh Karunaratne Date: Mon, 13 Feb 2023 10:13:32 +0530 Subject: [PATCH] Use `json_validate` in `Rules\Json` if available (#1394) [`json_validate` function](https://wiki.php.net/rfc/json_validate) [added in PHP 8.3](https://php.watch/versions/8.3/json_validate) validates a given string input to contain valid JSON without decoding it in memory. This adds a function availability check to `Rules\Json`, and uses the new function instead of decoding the given input, followed by a last-error check. --- library/Rules/Json.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/Rules/Json.php b/library/Rules/Json.php index 1dc5a9e1..0b03fb93 100644 --- a/library/Rules/Json.php +++ b/library/Rules/Json.php @@ -36,6 +36,10 @@ final class Json extends AbstractRule return false; } + if (function_exists('json_validate')) { + return json_validate($input); + } + json_decode($input); return json_last_error() === JSON_ERROR_NONE;