Fix json-encoding when JSON_THROW_ON_ERROR is used
This commit is contained in:
parent
2ae0580eea
commit
d18f42c409
@ -186,11 +186,6 @@ class JsonDescriptor extends Descriptor
|
|||||||
{
|
{
|
||||||
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
|
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
|
||||||
|
|
||||||
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $flags)) {
|
|
||||||
// Work around https://bugs.php.net/77997
|
|
||||||
json_encode(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n");
|
$this->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,11 +99,6 @@ class JsonDescriptor extends Descriptor
|
|||||||
{
|
{
|
||||||
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
|
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
|
||||||
|
|
||||||
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $flags)) {
|
|
||||||
// Work around https://bugs.php.net/77997
|
|
||||||
json_encode(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->write(json_encode($data, $flags));
|
$this->write(json_encode($data, $flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,11 +83,6 @@ class JsonDescriptor extends Descriptor
|
|||||||
{
|
{
|
||||||
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
|
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
|
||||||
|
|
||||||
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $flags)) {
|
|
||||||
// Work around https://bugs.php.net/77997
|
|
||||||
json_encode(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->output->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n");
|
$this->output->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,11 +153,6 @@ class JsonResponse extends Response
|
|||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $this->encodingOptions)) {
|
|
||||||
// Work around https://bugs.php.net/77997
|
|
||||||
json_encode(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$data = json_encode($data, $this->encodingOptions);
|
$data = json_encode($data, $this->encodingOptions);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -166,6 +161,10 @@ class JsonResponse extends Response
|
|||||||
}
|
}
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $this->encodingOptions)) {
|
||||||
|
return $this->setJson($data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,15 @@ class JsonDecode implements DecoderInterface
|
|||||||
$recursionDepth = $context['json_decode_recursion_depth'];
|
$recursionDepth = $context['json_decode_recursion_depth'];
|
||||||
$options = $context['json_decode_options'];
|
$options = $context['json_decode_options'];
|
||||||
|
|
||||||
$decodedData = json_decode($data, $associative, $recursionDepth, $options);
|
try {
|
||||||
|
$decodedData = json_decode($data, $associative, $recursionDepth, $options);
|
||||||
|
} catch (\JsonException $e) {
|
||||||
|
throw new NotEncodableValueException($e->getMessage(), 0, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $options)) {
|
||||||
|
return $decodedData;
|
||||||
|
}
|
||||||
|
|
||||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
if (JSON_ERROR_NONE !== json_last_error()) {
|
||||||
throw new NotEncodableValueException(json_last_error_msg());
|
throw new NotEncodableValueException(json_last_error_msg());
|
||||||
|
@ -36,13 +36,12 @@ class JsonEncode implements EncoderInterface
|
|||||||
{
|
{
|
||||||
$context = $this->resolveContext($context);
|
$context = $this->resolveContext($context);
|
||||||
|
|
||||||
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $context['json_encode_options'])) {
|
|
||||||
// Work around https://bugs.php.net/77997
|
|
||||||
json_encode(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
$encodedJson = json_encode($data, $context['json_encode_options']);
|
$encodedJson = json_encode($data, $context['json_encode_options']);
|
||||||
|
|
||||||
|
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $context['json_encode_options'])) {
|
||||||
|
return $encodedJson;
|
||||||
|
}
|
||||||
|
|
||||||
if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($context['json_encode_options'] & JSON_PARTIAL_OUTPUT_ON_ERROR))) {
|
if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($context['json_encode_options'] & JSON_PARTIAL_OUTPUT_ON_ERROR))) {
|
||||||
throw new NotEncodableValueException(json_last_error_msg());
|
throw new NotEncodableValueException(json_last_error_msg());
|
||||||
}
|
}
|
||||||
|
@ -31,11 +31,6 @@ class JsonFileDumper extends FileDumper
|
|||||||
$flags = \defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0;
|
$flags = \defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $flags)) {
|
|
||||||
// Work around https://bugs.php.net/77997
|
|
||||||
json_encode(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return json_encode($messages->all($domain), $flags);
|
return json_encode($messages->all($domain), $flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user