Page MenuHomePhabricator

D12725.id30574.diff
No OneTemporary

D12725.id30574.diff

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();

File Metadata

Mime Type
text/plain
Expires
Mon, Apr 21, 8:33 PM (1 d, 18 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7225991
Default Alt Text
D12725.id30574.diff (1 KB)

Event Timeline