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

Fix an issue where "Export Data" could fail if a user had a nonempty custom policy preference

Summary:
The "Export Data" workflow incorrectly uses the "Policy Favorites" setting to choose a default export format. This is just a copy/paste error; the correct setting exists and is unused.

If the setting value is an array (as the "Policy Favorites" value often is), we try to use it as an array index. This generates a runtime exception after D21044.

```
[2020-06-16 06:32:12] EXCEPTION: (RuntimeException) Illegal offset type in isset or empty at [<arcanist>/src/error/PhutilErrorHandler.php:263]
  #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer, array) called at [<phabricator>/src/applications/search/controller/PhabricatorApplicationSearchController.php:460]
```

  - Use the correct setting.
  - Make sure the value we read is a string.

Test Plan:
  - Used "Export Data" with a nonempty, array-valued "Policy Favorites" setting.
    - Before: runtime exception.
    - After: clean export.
  - Used "Export Data" again, saw my selection from the first time persisted.

Differential Revision: https://secure.phabricator.com/D21361
This commit is contained in:
epriestley 2020-06-16 06:35:10 -07:00
parent d203a1004c
commit 8c7f114b4d

View file

@ -964,8 +964,14 @@ final class PhabricatorApplicationSearchController
private function readExportFormatPreference() {
$viewer = $this->getViewer();
$export_key = PhabricatorPolicyFavoritesSetting::SETTINGKEY;
return $viewer->getUserSetting($export_key);
$export_key = PhabricatorExportFormatSetting::SETTINGKEY;
$value = $viewer->getUserSetting($export_key);
if (is_string($value)) {
return $value;
}
return '';
}
private function writeExportFormatPreference($value) {
@ -976,7 +982,7 @@ final class PhabricatorApplicationSearchController
return;
}
$export_key = PhabricatorPolicyFavoritesSetting::SETTINGKEY;
$export_key = PhabricatorExportFormatSetting::SETTINGKEY;
$preferences = PhabricatorUserPreferences::loadUserPreferences($viewer);
$editor = id(new PhabricatorUserPreferencesEditor())