Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14011465
D12679.id30444.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D12679.id30444.diff
View Options
diff --git a/src/auth/PhutilAmazonAuthAdapter.php b/src/auth/PhutilAmazonAuthAdapter.php
--- a/src/auth/PhutilAmazonAuthAdapter.php
+++ b/src/auth/PhutilAmazonAuthAdapter.php
@@ -68,14 +68,13 @@
$future = new HTTPSFuture($uri);
list($body) = $future->resolvex();
- $data = json_decode($body, true);
- if (!is_array($data)) {
- throw new Exception(
- 'Expected valid JSON response from Amazon account data request, '.
- 'got: '.$body);
+ try {
+ return phutil_json_decode($body);
+ } catch (PhutilJSONParserException $ex) {
+ throw new PhutilProxyException(
+ pht('Expected valid JSON response from Amazon account data request.'),
+ $ex);
}
-
- return $data;
}
}
diff --git a/src/auth/PhutilDisqusAuthAdapter.php b/src/auth/PhutilDisqusAuthAdapter.php
--- a/src/auth/PhutilDisqusAuthAdapter.php
+++ b/src/auth/PhutilDisqusAuthAdapter.php
@@ -71,14 +71,14 @@
$future->setMethod('GET');
list($body) = $future->resolvex();
- $data = json_decode($body, true);
- if (!is_array($data)) {
- throw new Exception(
- 'Expected valid JSON response from Disqus account data request, '.
- 'got: '.$body);
+ try {
+ $data = phutil_json_decode($body);
+ return $data['response'];
+ } catch (PhutilJSONParserException $ex) {
+ throw new PhutilProxyException(
+ pht('Expected valid JSON response from Disqus account data request.'),
+ $ex);
}
-
- return $data['response'];
}
}
diff --git a/src/auth/PhutilFacebookAuthAdapter.php b/src/auth/PhutilFacebookAuthAdapter.php
--- a/src/auth/PhutilFacebookAuthAdapter.php
+++ b/src/auth/PhutilFacebookAuthAdapter.php
@@ -88,11 +88,13 @@
$uri->setQueryParam('fields', implode(',', $fields));
list($body) = id(new HTTPSFuture($uri))->resolvex();
- $data = json_decode($body, true);
- if (!is_array($data)) {
- throw new Exception(
- 'Expected valid JSON response from Facebook account data request, '.
- 'got: '.$body);
+ $data = null;
+ try {
+ $data = phutil_json_decode($body);
+ } catch (PhutilJSONParserException $ex) {
+ throw new PhutilProxyException(
+ pht('Expected valid JSON response from Facebook account data request.'),
+ $ex);
}
if ($this->requireSecureBrowsing) {
diff --git a/src/auth/PhutilGitHubAuthAdapter.php b/src/auth/PhutilGitHubAuthAdapter.php
--- a/src/auth/PhutilGitHubAuthAdapter.php
+++ b/src/auth/PhutilGitHubAuthAdapter.php
@@ -60,14 +60,13 @@
list($body) = $future->resolvex();
- $data = json_decode($body, true);
- if (!is_array($data)) {
- throw new Exception(
- 'Expected valid JSON response from GitHub account data request, '.
- 'got: '.$body);
+ try{
+ return phutil_json_decode($body);
+ } catch (PhutilJSONParserException $ex) {
+ throw new PhutilProxyException(
+ pht('Expected valid JSON response from GitHub account data request.'),
+ $ex);
}
-
- return $data;
}
}
diff --git a/src/auth/PhutilGoogleAuthAdapter.php b/src/auth/PhutilGoogleAuthAdapter.php
--- a/src/auth/PhutilGoogleAuthAdapter.php
+++ b/src/auth/PhutilGoogleAuthAdapter.php
@@ -105,14 +105,13 @@
throw $status;
}
- $data = json_decode($body, true);
- if (!is_array($data)) {
- throw new Exception(
- 'Expected valid JSON response from Google account data request, '.
- 'got: '.$body);
+ try {
+ return phutil_json_decode($body);
+ } catch (PhutilJSONParserException $ex) {
+ throw new PhutilProxyException(
+ pht('Expected valid JSON response from Google account data request.'),
+ $ex);
}
-
- return $data;
}
private function tryToThrowSpecializedError($status, $raw_body) {
diff --git a/src/auth/PhutilPersonaAuthAdapter.php b/src/auth/PhutilPersonaAuthAdapter.php
--- a/src/auth/PhutilPersonaAuthAdapter.php
+++ b/src/auth/PhutilPersonaAuthAdapter.php
@@ -44,9 +44,13 @@
->addHeader('Content-Type', 'application/json')
->resolvex();
- $response = json_decode($body, true);
- if (!is_array($response)) {
- throw new Exception("Unexpected Persona response: {$body}");
+ $response = null;
+ try {
+ $response = phutil_json_decode($body);
+ } catch (PhutilJSONParserException $ex) {
+ throw new PhutilProxyException(
+ pht('Unexpected Persona response.'),
+ $ex);
}
$audience = idx($response, 'audience');
diff --git a/src/auth/PhutilPhabricatorAuthAdapter.php b/src/auth/PhutilPhabricatorAuthAdapter.php
--- a/src/auth/PhutilPhabricatorAuthAdapter.php
+++ b/src/auth/PhutilPhabricatorAuthAdapter.php
@@ -83,14 +83,16 @@
->setQueryParam('access_token', $this->getAccessToken());
list($body) = id(new HTTPSFuture($uri))->resolvex();
- $data = json_decode($body, true);
- if (!is_array($data)) {
+ try {
+ $data = phutil_json_decode($body);
+ return $data['result'];
+ } catch (PhutilJSONParserException $ex) {
throw new Exception(
- 'Expected valid JSON response from Phabricator user.whoami request, '.
- 'got: '.$body);
+ pht(
+ 'Expected valid JSON response from Phabricator %s request.',
+ 'user.whoami'),
+ $ex);
}
-
- return $data['result'];
}
private function getPhabricatorURI($path) {
diff --git a/src/channel/PhutilJSONProtocolChannel.php b/src/channel/PhutilJSONProtocolChannel.php
--- a/src/channel/PhutilJSONProtocolChannel.php
+++ b/src/channel/PhutilJSONProtocolChannel.php
@@ -74,11 +74,12 @@
$data = substr($this->buf, 0, $this->byteLengthOfNextChunk);
$this->buf = substr($this->buf, $this->byteLengthOfNextChunk);
- $obj = json_decode($data, true);
- if (!is_array($obj)) {
- throw new Exception("Failed to decode JSON object: {$data}");
- } else {
- $objects[] = $obj;
+ try {
+ $objects[] = phutil_json_decode($data);
+ } catch (PhutilJSONParserException $ex) {
+ throw new PhutilProxyException(
+ pht('Failed to decode JSON object.'),
+ $ex);
}
$this->mode = self::MODE_LENGTH;
diff --git a/src/conduit/ConduitFuture.php b/src/conduit/ConduitFuture.php
--- a/src/conduit/ConduitFuture.php
+++ b/src/conduit/ConduitFuture.php
@@ -43,11 +43,15 @@
$raw = substr($raw, strlen($shield));
}
- $data = json_decode($raw, true);
- if (!is_array($data)) {
- throw new Exception(
- "Host returned HTTP/200, but invalid JSON data in response to ".
- "a Conduit method call:\n{$raw}");
+ $data = null;
+ try {
+ $data = phutil_json_decode($raw);
+ } catch (PhutilJSONParserException $ex) {
+ throw new PhutilProxyException(
+ pht(
+ 'Host returned HTTP/200, but invalid JSON data in response to '.
+ 'a Conduit method call.'),
+ $ex);
}
if ($data['error_code']) {
diff --git a/src/future/asana/PhutilAsanaFuture.php b/src/future/asana/PhutilAsanaFuture.php
--- a/src/future/asana/PhutilAsanaFuture.php
+++ b/src/future/asana/PhutilAsanaFuture.php
@@ -61,9 +61,13 @@
throw $status;
}
- $data = json_decode($body, true);
- if (!is_array($data)) {
- throw new Exception("Expected JSON response from Asana, got: {$body}");
+ $data = null;
+ try {
+ $data = phutil_json_decode($body);
+ } catch (PhutilJSONParserException $ex) {
+ throw new PhutilProxyException(
+ pht('Expected JSON response from Asana.'),
+ $ex);
}
if (idx($data, 'errors')) {
diff --git a/src/future/exec/ExecFuture.php b/src/future/exec/ExecFuture.php
--- a/src/future/exec/ExecFuture.php
+++ b/src/future/exec/ExecFuture.php
@@ -446,8 +446,9 @@
$stdout,
$stderr);
}
- $object = json_decode($stdout, true);
- if (!is_array($object)) {
+ try {
+ return phutil_json_decode($stdout);
+ } catch (PhutilJSONParserException $ex) {
$cmd = $this->command;
throw new CommandException(
"JSON command '{$cmd}' did not produce a valid JSON object on stdout: ".
@@ -457,7 +458,6 @@
$stdout,
$stderr);
}
- return $object;
}
/**
diff --git a/src/future/oauth/PhutilOAuth1Future.php b/src/future/oauth/PhutilOAuth1Future.php
--- a/src/future/oauth/PhutilOAuth1Future.php
+++ b/src/future/oauth/PhutilOAuth1Future.php
@@ -270,11 +270,12 @@
$result = $this->getProxiedFuture()->resolvex();
$result = $this->didReceiveResult($result);
list($body) = $result;
- $data = json_decode($body, true);
- if (!is_array($data)) {
- throw new Exception("Expected JSON, got: {$body}!");
+
+ try {
+ return phutil_json_decode($body);
+ } catch (PhutilJSONParserException $ex) {
+ throw new PhutilProxyException(pht('Expected JSON.'), $ex);
}
- return $data;
}
diff --git a/src/future/twitch/PhutilTwitchFuture.php b/src/future/twitch/PhutilTwitchFuture.php
--- a/src/future/twitch/PhutilTwitchFuture.php
+++ b/src/future/twitch/PhutilTwitchFuture.php
@@ -73,9 +73,13 @@
throw $status;
}
- $data = json_decode($body, true);
- if (!is_array($data)) {
- throw new Exception("Expected JSON response from Twitch, got: {$body}");
+ $data = null;
+ try {
+ $data = phutil_json_decode($body);
+ } catch (PhutilJSONParserException $ex) {
+ throw new PhutilProxyException(
+ pht('Expected JSON response from Twitch.'),
+ $ex);
}
if (idx($data, 'error')) {
diff --git a/src/parser/xhpast/__tests__/PHPASTParserTestCase.php b/src/parser/xhpast/__tests__/PHPASTParserTestCase.php
--- a/src/parser/xhpast/__tests__/PHPASTParserTestCase.php
+++ b/src/parser/xhpast/__tests__/PHPASTParserTestCase.php
@@ -95,21 +95,27 @@
$dir = dirname(__FILE__).'/data/';
$expect = Filesystem::readFile($dir.$expect_name);
- $expect = json_decode($expect, true);
- if (!is_array($expect)) {
- throw new Exception(
+ $expect = null;
+ try {
+ $expect = phutil_json_decode($expect);
+ } catch (PhutilJSONParserException $ex) {
+ throw new PhutilProxyException(
pht(
'Test ".expect" file "%s" for test "%s" is not valid JSON.',
$expect_name,
- $name));
+ $name),
+ $ex);
}
- $stdout = json_decode($stdout, true);
- if (!is_array($stdout)) {
- throw new Exception(
+ $stdout = null;
+ try {
+ $stdout = phutil_json_decode($stdout);
+ } catch (PhutilJSONParserException $ex) {
+ throw new PhutilProxyException(
pht(
'Output for test file "%s" is not valid JSON.',
- $name));
+ $name),
+ $ex);
}
$json = new PhutilJSON();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 2, 1:50 AM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6756520
Default Alt Text
D12679.id30444.diff (10 KB)
Attached To
Mode
D12679: Use phutil_json_decode instead of json_decode
Attached
Detach File
Event Timeline
Log In to Comment