Page MenuHomePhabricator

"RemarkupField" returns "RemarkupValue" when editing defaults, which fails to survive serialization
Open, NormalPublic

Description

See PHI2203. After recent changes for file handling, editing the form defaults for a form which includes a Remarkup text field causes it to emit a "RemarkupValue" as a default value. This value can't be serialized to the database and ends up stored as an empty array, which fatals when loaded.

The immediate issue is easy to fix, but ideally this sort of thing should fail loudly at serialization time, rather than once the database has already been poisoned.

Event Timeline

epriestley triaged this task as Normal priority.Tue, Jun 14, 1:09 PM
epriestley created this task.

...ideally this sort of thing should fail loudly at serialization time...

This is because json_encode() is extremely forgiving of inputs. Behavior can be improved significantly like this:

diff --git a/src/object/Phobject.php b/src/object/Phobject.php
index 4d799306..f7df4798 100644
--- a/src/object/Phobject.php
+++ b/src/object/Phobject.php
@@ -17,7 +17,10 @@
  * (Legitimately iterable subclasses can provide a working implementation of
  * Iterator instead.)
  */
-abstract class Phobject implements Iterator {
+abstract class Phobject
+  implements
+    Iterator,
+    JsonSerializable {
 
   public function __get($name) {
     throw new DomainException(
@@ -33,6 +36,13 @@ abstract class Phobject implements Iterator {
         get_class($this).'::'.$name));
   }
 
+  public function jsonSerialize() {
+    throw new DomainException(
+      pht(
+        'Attempt to serialize unserializable object (of class "%s") to JSON.',
+        get_class($this)));
+  }
+
   #[\ReturnTypeWillChange]
   public function current() {
     $this->throwOnAttemptedIteration();

...but this is a bit risky, so I'm not going to press my luck for now.