mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
PropertyModifierJsonDecode: explicitly fail for...
...non-string inputs fixes #2810
This commit is contained in:
parent
76509bb7c8
commit
742013673e
@ -38,6 +38,7 @@ This version hasn't been released yet
|
|||||||
* FIX: synchronizing Service (and -Set) Templates has been fixed (#2745, #2217)
|
* FIX: synchronizing Service (and -Set) Templates has been fixed (#2745, #2217)
|
||||||
* FIX: null properties with Sync policy "ignore" are now being ignored (#2657)
|
* FIX: null properties with Sync policy "ignore" are now being ignored (#2657)
|
||||||
* FIX: Import Source shows available columns for Core API Import (#2763)
|
* FIX: Import Source shows available columns for Core API Import (#2763)
|
||||||
|
* FIX: JSON-decode now explicitly fails for non-string inputs (#2810)
|
||||||
|
|
||||||
# Configuration Baskets
|
# Configuration Baskets
|
||||||
* FEATURE: it's now possible to upload snapshots for existing baskets (#1952)
|
* FEATURE: it's now possible to upload snapshots for existing baskets (#1952)
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\PropertyModifier;
|
namespace Icinga\Module\Director\PropertyModifier;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use gipfl\Json\JsonString;
|
||||||
use Icinga\Exception\InvalidPropertyException;
|
use Icinga\Exception\InvalidPropertyException;
|
||||||
use Icinga\Module\Director\Exception\JsonException;
|
|
||||||
use Icinga\Module\Director\Hook\PropertyModifierHook;
|
use Icinga\Module\Director\Hook\PropertyModifierHook;
|
||||||
use Icinga\Module\Director\Web\Form\QuickForm;
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
||||||
|
|
||||||
@ -38,16 +39,22 @@ class PropertyModifierJsonDecode extends PropertyModifierHook
|
|||||||
/**
|
/**
|
||||||
* @param $value
|
* @param $value
|
||||||
* @return mixed|null
|
* @return mixed|null
|
||||||
* @throws InvalidPropertyException
|
* @throws InvalidPropertyException|\gipfl\Json\JsonDecodeException
|
||||||
*/
|
*/
|
||||||
public function transform($value)
|
public function transform($value)
|
||||||
{
|
{
|
||||||
if (null === $value) {
|
if (null === $value) {
|
||||||
return $value;
|
return null;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
$decoded = @json_decode($value);
|
if (is_string($value)) {
|
||||||
if ($decoded === null && JSON_ERROR_NONE !== json_last_error()) {
|
$decoded = JsonString::decode($value);
|
||||||
|
} else {
|
||||||
|
throw new InvalidPropertyException(
|
||||||
|
'JSON decode expects a string, got ' . gettype($value)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
switch ($this->getSetting('on_failure')) {
|
switch ($this->getSetting('on_failure')) {
|
||||||
case 'null':
|
case 'null':
|
||||||
return null;
|
return null;
|
||||||
@ -55,11 +62,7 @@ class PropertyModifierJsonDecode extends PropertyModifierHook
|
|||||||
return $value;
|
return $value;
|
||||||
case 'fail':
|
case 'fail':
|
||||||
default:
|
default:
|
||||||
throw new InvalidPropertyException(
|
throw $e;
|
||||||
'JSON decoding failed with "%s" for %s',
|
|
||||||
JsonException::getJsonErrorMessage(json_last_error()),
|
|
||||||
substr($value, 0, 128)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user