Repository navigation
Conversation
| public function formatDefaultValueForDB(mixed $value): string | ||
| { | ||
| // For cloned questions, the value may already be encoded, do not re-encode it. | ||
| if (is_string($value) && is_array(\json_decode($value, true))) { |
There was a problem hiding this comment.
Regression but minor : guessing from the shape of the value whether it is "already encoded" misclassifies text defaults that happen to be valid JSON (e.g. [1,2] or {} in a text/textarea field are stored raw and rendered as Array). Unlikely in practice, but handling the decoding in the clone path only would avoid the guesswork and also fix the scalar case below.
| $default_value = json_decode($question->fields['default_value'], true); | ||
| if (is_string($default_value)) { | ||
| $decoded = \json_decode($default_value, true); | ||
| if (is_array($decoded)) { |
There was a problem hiding this comment.
Scalar defaults are still double-encoded on clone.
To reproduce : add a Fields question on a text field with the default hello, then duplicate the form. The copy shows "hello" with quotes and each further duplication adds another level of escaping (" \ "hello \ "", ...). The same applies to textarea, number, url and date fields.
Also, should existing forms already corrupted by previous clones be repaired (migration)? Tests covering the clone of scalar and dropdown defaults would help too.
Checklist before requesting a review
Please delete options that are not relevant.
Description
Fix rendering error
unknown named parametersfor duplicated formScreenshots (if appropriate):