mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 21:40:55 +01:00
Fix error in PhabricatorSetupIssueView
Summary: - Move `prettyPrintJSON()` and make it static. - Use it from `PhabricatorSetupIssueView` - Update other `config/` places that use it to call it from the new class. This fixes a bug in `PhabricatorSetupIssueView` which showed up if the value was an array and couldn't be rendered by `phutil_escape_html()`. Test Plan: - Rendered some config options. - Went to /config/issue/config.unknown.phame.skins/ without error. Reviewers: epriestley, btrahan, chad Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2255 Differential Revision: https://secure.phabricator.com/D4411
This commit is contained in:
parent
08687c0b17
commit
76c10f497f
6 changed files with 27 additions and 20 deletions
|
@ -706,6 +706,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorConfigGroupController' => 'applications/config/controller/PhabricatorConfigGroupController.php',
|
||||
'PhabricatorConfigIssueListController' => 'applications/config/controller/PhabricatorConfigIssueListController.php',
|
||||
'PhabricatorConfigIssueViewController' => 'applications/config/controller/PhabricatorConfigIssueViewController.php',
|
||||
'PhabricatorConfigJSON' => 'applications/config/json/PhabricatorConfigJSON.php',
|
||||
'PhabricatorConfigListController' => 'applications/config/controller/PhabricatorConfigListController.php',
|
||||
'PhabricatorConfigLocalSource' => 'infrastructure/env/PhabricatorConfigLocalSource.php',
|
||||
'PhabricatorConfigManagementSetWorkflow' => 'infrastructure/env/management/PhabricatorConfigManagementSetWorkflow.php',
|
||||
|
|
|
@ -21,20 +21,4 @@ abstract class PhabricatorConfigController extends PhabricatorController {
|
|||
return $this->buildSideNavView(null, true)->getMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
* Properly format a JSON value.
|
||||
*
|
||||
* @param wild Any value, but should be a raw value, not a string of JSON.
|
||||
* @return string
|
||||
*/
|
||||
public function prettyPrintJSON($value) {
|
||||
// Check not only that it's an array, but that it's an "unnatural" array
|
||||
// meaning that the keys aren't 0 -> size_of_array.
|
||||
if (is_array($value) && array_keys($value) != range(0, count($value) - 1)) {
|
||||
return id(new PhutilJSON())->encodeFormatted($value);
|
||||
} else {
|
||||
return json_encode($value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -330,7 +330,7 @@ final class PhabricatorConfigEditController
|
|||
case 'list<string>':
|
||||
return implode("\n", nonempty($value, array()));
|
||||
default:
|
||||
return $this->prettyPrintJSON($value);
|
||||
return PhabricatorConfigJSON::prettyPrintJSON($value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -462,7 +462,8 @@ final class PhabricatorConfigEditController
|
|||
if (!array_key_exists($option->getKey(), $value)) {
|
||||
$value = '<em>'.pht('(empty)').'</em>';
|
||||
} else {
|
||||
$value = $this->prettyPrintJSON($value[$option->getKey()]);
|
||||
$value = PhabricatorConfigJSON::prettyPrintJSON(
|
||||
$value[$option->getKey()]);
|
||||
}
|
||||
|
||||
$table[] = '<tr>';
|
||||
|
|
|
@ -74,7 +74,8 @@ final class PhabricatorConfigGroupController
|
|||
|
||||
if (!$option->getHidden()) {
|
||||
$current_value = PhabricatorEnv::getEnvConfig($option->getKey());
|
||||
$current_value = $this->prettyPrintJSON($current_value);
|
||||
$current_value = PhabricatorConfigJSON::prettyPrintJSON(
|
||||
$current_value);
|
||||
$current_value = phutil_render_tag(
|
||||
'div',
|
||||
array(
|
||||
|
|
19
src/applications/config/json/PhabricatorConfigJSON.php
Normal file
19
src/applications/config/json/PhabricatorConfigJSON.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorConfigJSON {
|
||||
/**
|
||||
* Properly format a JSON value.
|
||||
*
|
||||
* @param wild Any value, but should be a raw value, not a string of JSON.
|
||||
* @return string
|
||||
*/
|
||||
public static function prettyPrintJSON($value) {
|
||||
// Check not only that it's an array, but that it's an "unnatural" array
|
||||
// meaning that the keys aren't 0 -> size_of_array.
|
||||
if (is_array($value) && array_keys($value) != range(0, count($value) - 1)) {
|
||||
return id(new PhutilJSON())->encodeFormatted($value);
|
||||
} else {
|
||||
return json_encode($value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -133,7 +133,8 @@ final class PhabricatorSetupIssueView extends AphrontView {
|
|||
} else if ($value === true) {
|
||||
$value = '<em>true</em>';
|
||||
} else {
|
||||
$value = phutil_escape_html($value);
|
||||
$value = phutil_escape_html(
|
||||
PhabricatorConfigJSON::prettyPrintJSON($value));
|
||||
}
|
||||
|
||||
$table[] = '<td>'.$value.'</td>';
|
||||
|
|
Loading…
Reference in a new issue