Skip to content

Commit 9426765

Browse files
author
epriestley
committedJun 14, 2022
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
1 parent 1fc04e2 commit 9426765

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed
 

‎src/applications/transactions/editfield/PhabricatorRemarkupEditField.php

+26
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,32 @@ public function getValueForTransaction() {
2929
return $value;
3030
}
3131

32+
public function getValueForDefaults() {
33+
$value = parent::getValueForDefaults();
34+
35+
if ($value instanceof RemarkupValue) {
36+
$value = $value->getCorpus();
37+
}
38+
39+
return $value;
40+
}
41+
42+
protected function getDefaultValueFromConfiguration($value) {
43+
44+
// See T13685. After changes to file attachment handling, the database
45+
// was briefly poisoned with "array()" values as defaults.
46+
47+
try {
48+
$value = phutil_string_cast($value);
49+
} catch (Exception $ex) {
50+
$value = '';
51+
} catch (Throwable $ex) {
52+
$value = '';
53+
}
54+
55+
return $value;
56+
}
57+
3258
public function getMetadata() {
3359
$defaults = array();
3460

‎src/view/form/control/AphrontFormTextAreaControl.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function renderInput() {
7373

7474
// NOTE: This needs to be string cast, because if we pass `null` the
7575
// tag will be self-closed and some browsers aren't thrilled about that.
76-
$value = (string)$this->getValue();
76+
$value = phutil_string_cast($this->getValue());
7777

7878
// NOTE: We also need to prefix the string with a newline, because browsers
7979
// ignore a newline immediately after a <textarea> tag, so they'll eat

0 commit comments

Comments
 (0)
Failed to load comments.