1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +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:
Ricky Elrod 2013-01-11 15:28:33 -08:00 committed by epriestley
parent 08687c0b17
commit 76c10f497f
6 changed files with 27 additions and 20 deletions

View file

@ -706,6 +706,7 @@ phutil_register_library_map(array(
'PhabricatorConfigGroupController' => 'applications/config/controller/PhabricatorConfigGroupController.php', 'PhabricatorConfigGroupController' => 'applications/config/controller/PhabricatorConfigGroupController.php',
'PhabricatorConfigIssueListController' => 'applications/config/controller/PhabricatorConfigIssueListController.php', 'PhabricatorConfigIssueListController' => 'applications/config/controller/PhabricatorConfigIssueListController.php',
'PhabricatorConfigIssueViewController' => 'applications/config/controller/PhabricatorConfigIssueViewController.php', 'PhabricatorConfigIssueViewController' => 'applications/config/controller/PhabricatorConfigIssueViewController.php',
'PhabricatorConfigJSON' => 'applications/config/json/PhabricatorConfigJSON.php',
'PhabricatorConfigListController' => 'applications/config/controller/PhabricatorConfigListController.php', 'PhabricatorConfigListController' => 'applications/config/controller/PhabricatorConfigListController.php',
'PhabricatorConfigLocalSource' => 'infrastructure/env/PhabricatorConfigLocalSource.php', 'PhabricatorConfigLocalSource' => 'infrastructure/env/PhabricatorConfigLocalSource.php',
'PhabricatorConfigManagementSetWorkflow' => 'infrastructure/env/management/PhabricatorConfigManagementSetWorkflow.php', 'PhabricatorConfigManagementSetWorkflow' => 'infrastructure/env/management/PhabricatorConfigManagementSetWorkflow.php',

View file

@ -21,20 +21,4 @@ abstract class PhabricatorConfigController extends PhabricatorController {
return $this->buildSideNavView(null, true)->getMenu(); 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);
}
}
} }

View file

@ -330,7 +330,7 @@ final class PhabricatorConfigEditController
case 'list<string>': case 'list<string>':
return implode("\n", nonempty($value, array())); return implode("\n", nonempty($value, array()));
default: default:
return $this->prettyPrintJSON($value); return PhabricatorConfigJSON::prettyPrintJSON($value);
} }
} }
@ -462,7 +462,8 @@ final class PhabricatorConfigEditController
if (!array_key_exists($option->getKey(), $value)) { if (!array_key_exists($option->getKey(), $value)) {
$value = '<em>'.pht('(empty)').'</em>'; $value = '<em>'.pht('(empty)').'</em>';
} else { } else {
$value = $this->prettyPrintJSON($value[$option->getKey()]); $value = PhabricatorConfigJSON::prettyPrintJSON(
$value[$option->getKey()]);
} }
$table[] = '<tr>'; $table[] = '<tr>';

View file

@ -74,7 +74,8 @@ final class PhabricatorConfigGroupController
if (!$option->getHidden()) { if (!$option->getHidden()) {
$current_value = PhabricatorEnv::getEnvConfig($option->getKey()); $current_value = PhabricatorEnv::getEnvConfig($option->getKey());
$current_value = $this->prettyPrintJSON($current_value); $current_value = PhabricatorConfigJSON::prettyPrintJSON(
$current_value);
$current_value = phutil_render_tag( $current_value = phutil_render_tag(
'div', 'div',
array( array(

View 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);
}
}
}

View file

@ -133,7 +133,8 @@ final class PhabricatorSetupIssueView extends AphrontView {
} else if ($value === true) { } else if ($value === true) {
$value = '<em>true</em>'; $value = '<em>true</em>';
} else { } else {
$value = phutil_escape_html($value); $value = phutil_escape_html(
PhabricatorConfigJSON::prettyPrintJSON($value));
} }
$table[] = '<td>'.$value.'</td>'; $table[] = '<td>'.$value.'</td>';