Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15522521
D12725.id30574.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D12725.id30574.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D12725: Make phutil_json_decode more powerful
Attached
Detach File
Event Timeline
Log In to Comment