diff --git a/src/utils/__tests__/PhutilUtilsTestCase.php b/src/utils/__tests__/PhutilUtilsTestCase.php --- a/src/utils/__tests__/PhutilUtilsTestCase.php +++ b/src/utils/__tests__/PhutilUtilsTestCase.php @@ -505,6 +505,11 @@ public function testPhutilJSONDecode() { $valid_cases = array( + 'null' => null, + 'false' => false, + 'true' => true, + '"string"' => 'string', + '123' => 123, '{}' => array(), '[]' => array(), '[1, 2]' => array(1, 2), @@ -517,11 +522,10 @@ } $invalid_cases = array( - '', - '"a"', + 'nil', '{,}', - 'null', - '"null"', + '[,]', + '{', ); foreach ($invalid_cases as $input) { diff --git a/src/utils/utils.php b/src/utils/utils.php --- a/src/utils/utils.php +++ b/src/utils/utils.php @@ -1046,7 +1046,7 @@ function phutil_json_decode($string) { $result = @json_decode($string, true); - if (!is_array($result)) { + if ($result === null && $string !== 'null') { // Failed to decode the JSON. Try to use @{class:PhutilJSONParser} instead. // This will probably fail, but will throw a useful exception. $parser = new PhutilJSONParser();