From 8c7f114b4d905f2eb99be1ba8a7b9273b01e599a Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 16 Jun 2020 06:35:10 -0700 Subject: [PATCH] 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 [/src/error/PhutilErrorHandler.php:263] #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer, array) called at [/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 --- .../controller/PhabricatorApplicationSearchController.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/applications/search/controller/PhabricatorApplicationSearchController.php b/src/applications/search/controller/PhabricatorApplicationSearchController.php index 98d125fd33..290623e149 100644 --- a/src/applications/search/controller/PhabricatorApplicationSearchController.php +++ b/src/applications/search/controller/PhabricatorApplicationSearchController.php @@ -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()) -- 2.11.4.GIT