1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +01:00

Update callsites of phutil_json_decode.

Summary: Depends on D9634. `phutil_json_decode` now throws an exception on invalid JSON.

Test Plan: `arc unit`

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9640
This commit is contained in:
Joshua Spence 2014-06-21 00:39:37 +10:00
parent f7f8664456
commit a4a8cfa6d6
5 changed files with 19 additions and 28 deletions

View file

@ -13,19 +13,12 @@ abstract class PhabricatorConfigJSONOptionType
$display_value = $request->getStr('value'); $display_value = $request->getStr('value');
if (strlen($display_value)) { if (strlen($display_value)) {
$storage_value = phutil_json_decode($display_value); try {
if ($storage_value === null) { $storage_value = phutil_json_decode($display_value);
$this->validateOption($option, $storage_value);
} catch (Exception $ex) {
$e_value = pht('Invalid'); $e_value = pht('Invalid');
$errors[] = pht( $errors[] = $ex->getMessage();
'Configuration value should be specified in JSON. The provided '.
'value is not valid JSON.');
} else {
try {
$this->validateOption($option, $storage_value);
} catch (Exception $ex) {
$e_value = pht('Invalid');
$errors[] = $ex->getMessage();
}
} }
} else { } else {
$storage_value = null; $storage_value = null;

View file

@ -38,10 +38,7 @@ final class PhabricatorDashboardPanelTypeTabs
$config = $panel->getProperty('config'); $config = $panel->getProperty('config');
if (!is_array($config)) { if (!is_array($config)) {
// NOTE: The older version of this panel stored raw JSON. // NOTE: The older version of this panel stored raw JSON.
$config = phutil_json_decode($config, null); $config = phutil_json_decode($config);
if ($config === null) {
throw new Exception(pht('The configuration is not valid JSON.'));
}
} }
$list = id(new PHUIListView()) $list = id(new PHUIListView())

View file

@ -20,7 +20,11 @@ final class DifferentialAuditorsField
} }
public function setValueFromStorage($value) { public function setValueFromStorage($value) {
$this->setValue(phutil_json_decode($value)); try {
$this->setValue(phutil_json_decode($value));
} catch (PhutilJSONParserException $ex) {
$this->setValue(array());
}
return $this; return $this;
} }

View file

@ -26,7 +26,11 @@ final class DifferentialJIRAIssuesField
} }
public function setValueFromStorage($value) { public function setValueFromStorage($value) {
$this->setValue(phutil_json_decode($value)); try {
$this->setValue(phutil_json_decode($value));
} catch (PhutilJSONParserException $ex) {
$this->setValue(array());
}
return $this; return $this;
} }

View file

@ -23,16 +23,9 @@ final class DifferentialCommitMessageParserTestCase
} }
list($message, $fields, $output, $errors) = $parts; list($message, $fields, $output, $errors) = $parts;
$fields = phutil_json_decode($fields, null); $fields = phutil_json_decode($fields);
$output = phutil_json_decode($output, null); $output = phutil_json_decode($output);
$errors = phutil_json_decode($errors, null); $errors = phutil_json_decode($errors);
if ($fields === null || $output === null || $errors === null) {
throw new Exception(
pht(
'Expected test file "%s" to contain valid JSON in its sections.',
$file));
}
$parser = id(new DifferentialCommitMessageParser()) $parser = id(new DifferentialCommitMessageParser())
->setLabelMap($fields) ->setLabelMap($fields)