From 9c69d1a8adf18771e7f76a5d97d0b3ebd039c757 Mon Sep 17 00:00:00 2001 From: Marcin Michalski Date: Thu, 5 Sep 2024 18:12:03 +0200 Subject: [PATCH] Skip check when flag is set in --- lib/special_cases.php | 2 +- tests/JsonDecodeTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/JsonDecodeTest.php diff --git a/lib/special_cases.php b/lib/special_cases.php index a4e85a93..83a3949f 100644 --- a/lib/special_cases.php +++ b/lib/special_cases.php @@ -36,7 +36,7 @@ function json_decode(string $json, bool $assoc = false, int $depth = 512, int $flags = 0): mixed { $data = \json_decode($json, $assoc, $depth, $flags); - if (JSON_ERROR_NONE !== json_last_error()) { + if (!($flags & JSON_THROW_ON_ERROR) && JSON_ERROR_NONE !== json_last_error()) { throw JsonException::createFromPhpError(); } return $data; diff --git a/tests/JsonDecodeTest.php b/tests/JsonDecodeTest.php new file mode 100644 index 00000000..661fe178 --- /dev/null +++ b/tests/JsonDecodeTest.php @@ -0,0 +1,16 @@ +