Skip to content

Commit 7525730

Browse files
author
Nishanth Aravamudan
committed
Common/Transport/Utils.php: PHP7 JSON treats empty strings as syntax error
As per the changelog entry at php/php-src@9d037d5, PHP7 treats empty-string equivalents as syntax error, as they are not valid JSON. Special-case this in the json_decode path. Signed-off-by: Nishanth Aravamudan <[email protected]>
1 parent cd02545 commit 7525730

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Common/Transport/Utils.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ public static function jsonDecode(ResponseInterface $response, $assoc = true)
1818
JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded'
1919
];
2020

21-
$data = json_decode((string) $response->getBody(), $assoc);
21+
$responseBody = (string) $response->getBody();
22+
23+
if (strlen($responseBody) === 0) {
24+
return $responseBody;
25+
}
26+
27+
$data = json_decode($responseBody, $assoc);
2228

2329
if (JSON_ERROR_NONE !== json_last_error()) {
2430
$last = json_last_error();

0 commit comments

Comments
 (0)