From 9426765a2c6a149f5b0ed2d9132cd1e4e7ee152d Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 14 Jun 2022 09:29:55 -0700 Subject: [PATCH] Flatten "RemarkupValue" objects when setting field defaults for custom forms Summary: Ref T13685. "RemarkupEditField" uses a "RemarkupValue" internally, and it currently attempts to serialize into the database unsuccessfully. Instead, flatten the value before returning it for storage. Test Plan: - Edited the default description of a task in a custom form. Maniphest Tasks: T13685 Differential Revision: https://secure.phabricator.com/D21854 --- .../PhabricatorRemarkupEditField.php | 26 +++++++++++++++++++ .../control/AphrontFormTextAreaControl.php | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/applications/transactions/editfield/PhabricatorRemarkupEditField.php b/src/applications/transactions/editfield/PhabricatorRemarkupEditField.php index a299aa0b5c..a2e0debd39 100644 --- a/src/applications/transactions/editfield/PhabricatorRemarkupEditField.php +++ b/src/applications/transactions/editfield/PhabricatorRemarkupEditField.php @@ -29,6 +29,32 @@ final class PhabricatorRemarkupEditField return $value; } + public function getValueForDefaults() { + $value = parent::getValueForDefaults(); + + if ($value instanceof RemarkupValue) { + $value = $value->getCorpus(); + } + + return $value; + } + + protected function getDefaultValueFromConfiguration($value) { + + // See T13685. After changes to file attachment handling, the database + // was briefly poisoned with "array()" values as defaults. + + try { + $value = phutil_string_cast($value); + } catch (Exception $ex) { + $value = ''; + } catch (Throwable $ex) { + $value = ''; + } + + return $value; + } + public function getMetadata() { $defaults = array(); diff --git a/src/view/form/control/AphrontFormTextAreaControl.php b/src/view/form/control/AphrontFormTextAreaControl.php index 2665c6aaa7..e548916fbb 100644 --- a/src/view/form/control/AphrontFormTextAreaControl.php +++ b/src/view/form/control/AphrontFormTextAreaControl.php @@ -73,7 +73,7 @@ class AphrontFormTextAreaControl extends AphrontFormControl { // NOTE: This needs to be string cast, because if we pass `null` the // tag will be self-closed and some browsers aren't thrilled about that. - $value = (string)$this->getValue(); + $value = phutil_string_cast($this->getValue()); // NOTE: We also need to prefix the string with a newline, because browsers // ignore a newline immediately after a