1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-26 00:32:41 +01:00

Use phutil_json_decode instead of json_decode

Summary: Generally, `phutil_json_decode` should be preferred over `json_decode`.

Test Plan: Eyeballed.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: aurelijus, Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D12678
This commit is contained in:
Joshua Spence 2015-05-04 22:28:21 +10:00
parent 977baacc32
commit a4d33ef117
4 changed files with 12 additions and 16 deletions

View file

@ -132,14 +132,14 @@ final class ArcanistJSHintLinter extends ArcanistExternalLinter {
} }
protected function parseLinterOutput($path, $err, $stdout, $stderr) { protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$errors = json_decode($stdout, true); $errors = null;
try {
if (!is_array($errors)) { $error = phutil_json_decode($stdout);
} catch (PhutilJSONParserException $ex) {
// Something went wrong and we can't decode the output. Exit abnormally. // Something went wrong and we can't decode the output. Exit abnormally.
throw new RuntimeException( throw new PhutilProxyException(
"JSHint returned unparseable output.\n". pht('JSHint returned unparseable output.'),
"stdout:\n\n{$stdout}". $ex);
"stderr:\n\n{$stderr}");
} }
$messages = array(); $messages = array();

View file

@ -172,12 +172,7 @@ final class ArcanistPhpunitTestResultParser extends ArcanistTestResultParser {
$json = preg_replace('/}{\s*"/', '},{"', $json); $json = preg_replace('/}{\s*"/', '},{"', $json);
$json = '['.$json.']'; $json = '['.$json.']';
$json = json_decode($json); return phutil_json_decode($json);
if (!is_array($json)) {
throw new Exception('JSON could not be decoded');
}
return $json;
} }
} }

View file

@ -67,8 +67,9 @@ EOTEXT
pht('Waiting for JSON parameters on stdin...')); pht('Waiting for JSON parameters on stdin...'));
} }
$params = @file_get_contents('php://stdin'); $params = @file_get_contents('php://stdin');
$params = json_decode($params, true); try {
if (!is_array($params)) { $params = phutil_json_decode($params);
} catch (PhutilJSONParserException $ex) {
throw new ArcanistUsageException( throw new ArcanistUsageException(
pht('Provide method parameters on stdin as a JSON blob.')); pht('Provide method parameters on stdin as a JSON blob.'));
} }

View file

@ -1405,7 +1405,7 @@ abstract class ArcanistWorkflow extends Phobject {
if (!$file) { if (!$file) {
return array(); return array();
} }
return json_decode($file, true); return phutil_json_decode($file);
} }