From 5419d4428c86c488a43124f85e5407d7cbae6541 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:17:47 +0200 Subject: Adding upstream version 1.11.1. Signed-off-by: Daniel Baumann --- .../PropertyModifierJsonDecode.php | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'library/Director/PropertyModifier/PropertyModifierJsonDecode.php') diff --git a/library/Director/PropertyModifier/PropertyModifierJsonDecode.php b/library/Director/PropertyModifier/PropertyModifierJsonDecode.php index f6b9af8..4ab119a 100644 --- a/library/Director/PropertyModifier/PropertyModifierJsonDecode.php +++ b/library/Director/PropertyModifier/PropertyModifierJsonDecode.php @@ -2,8 +2,9 @@ namespace Icinga\Module\Director\PropertyModifier; +use Exception; +use gipfl\Json\JsonString; use Icinga\Exception\InvalidPropertyException; -use Icinga\Module\Director\Exception\JsonException; use Icinga\Module\Director\Hook\PropertyModifierHook; use Icinga\Module\Director\Web\Form\QuickForm; @@ -38,16 +39,22 @@ class PropertyModifierJsonDecode extends PropertyModifierHook /** * @param $value * @return mixed|null - * @throws InvalidPropertyException + * @throws InvalidPropertyException|\gipfl\Json\JsonDecodeException */ public function transform($value) { if (null === $value) { - return $value; + return null; } - - $decoded = @json_decode($value); - if ($decoded === null && JSON_ERROR_NONE !== json_last_error()) { + try { + if (is_string($value)) { + $decoded = JsonString::decode($value); + } else { + throw new InvalidPropertyException( + 'JSON decode expects a string, got ' . gettype($value) + ); + } + } catch (Exception $e) { switch ($this->getSetting('on_failure')) { case 'null': return null; @@ -55,11 +62,7 @@ class PropertyModifierJsonDecode extends PropertyModifierHook return $value; case 'fail': default: - throw new InvalidPropertyException( - 'JSON decoding failed with "%s" for %s', - JsonException::getJsonErrorMessage(json_last_error()), - substr($value, 0, 128) - ); + throw $e; } } -- cgit v1.2.3