Skip to content

Fix render error from duplicated form - #1301

Open
Lainow wants to merge 1 commit into
11.0/bugfixesfrom
fix-render-error-from-duplicated-form
Open

Lainow wants to merge 1 commit into
11.0/bugfixesfrom
fix-render-error-from-duplicated-form

Conversation

@Lainow

@Lainow Lainow commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Checklist before requesting a review

Please delete options that are not relevant.

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

  • It fixes !46925
  • Here is a brief description of what this PR does

Fix rendering error unknown named parameters for duplicated form

Screenshots (if appropriate):

image

@Lainow
Lainow requested a review from MyvTsv October 14, 2026 12:01
@Lainow Lainow self-assigned this Oct 14, 2026
@Lainow
Lainow requested review from Herafia and Mary-Clb October 14, 2026 12:02
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))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants