Avoid die while decoding erroneus json data

This commit is contained in:
fbsanchez 2021-05-07 14:15:16 +02:00
parent 454e6120e4
commit d160737fb2
1 changed files with 14 additions and 6 deletions

View File

@ -2462,12 +2462,20 @@ sub p_decode_json {
my ($pa_config, $data) = @_; my ($pa_config, $data) = @_;
my $decoded_data; my $decoded_data;
if ($JSON::VERSION > 2.90) { eval {
# Initialize JSON manager. local $SIG{__DIE__};
my $json = JSON->new->utf8->allow_nonref; if ($JSON::VERSION > 2.90) {
$decoded_data = $json->decode($data); # Initialize JSON manager.
} else { my $json = JSON->new->utf8->allow_nonref;
$decoded_data = decode_json($data); $decoded_data = $json->decode($data);
} else {
$decoded_data = decode_json($data);
}
};
if ($@){
if (defined($data)) {
logger($pa_config, 'Failed to decode data: '.$@, 5);
}
} }
return $decoded_data; return $decoded_data;