Skip to content

Commit

Permalink
Use safer json_decode_with_error function
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug authored Oct 4, 2021
1 parent dc8959a commit 4baf569
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/protobuf.php
Original file line number Diff line number Diff line change
Expand Up @@ -820,12 +820,13 @@ public static function FromString(string $str): mixed {
if ($str === "null") {
return null;
}
$data = \json_decode($str, true, 512, \JSON_FB_HACK_ARRAYS);
$error_data = null;
$data = \json_decode_with_error($str, inout $error_data, true, 512, \JSON_FB_HACK_ARRAYS);
if ($data !== null) {
return $data;
}
throw new \ProtobufException(
"json_decode failed; ".\json_last_error_msg(),
"json_decode failed; ".($error_data[1] ?? ''),
);
}

Expand Down

0 comments on commit 4baf569

Please sign in to comment.