Exception thrown when trying to submit element / wrapper attributes with invalid string

Created on 27 May 2025, 10 days ago

Problem/Motivation

When user accidentally fills in invalid YAML into the attributes input (type webform_codemirror) of a WebformElementAttributes form element and then tryies to submit the form, nothing happens. There no indication about any error, and especially if the webform field config form was open into a dialog (which is 99% of the cases I guess), the only feedback is the error counter of DevTools (if it is open).

Steps to reproduce

  1. Install Webform and Webform UI
  2. Log in as a user which has the "adminsiter webforms" permission.
  3. Visit the edit form of the default contact form replacement provided by Webform: admin/structure/webform/manage/contact
  4. Chose one of the elements (e.g. Your name) and click its "Edit" link.
  5. Chose the "Advanced" tab and open the details element of either Wrapper attributes or Element attributes.
  6. Fill in some invalid YAML string into the codemirror/textarea input with the label element custom attributes (YAML) or Wrapper custom attributes (YAML), e.g. this: is: invalid: YAML
  7. Hit the Save button

Expected: Form is reloaded and a validation error message is displayed (ideally, in the modal in the sidebar).
Actual: Exception is throw; user sees what described at the first point.

Proposed resolution

Add a try-catch around the YAML unserialization attempt in WebformElementAttributes::validateWebformElementAttributes.

Remaining tasks

Maybe the right tab and the right details should be open if there is an error with one of the inputs. I'Β§d solve this in another ticket.

User interface changes

Error message about the invalid YAML apperas on the page.

API changes

Nothing.

Data model changes

πŸ› Bug report
Status

Active

Version

6.3

Component

Code

Created by

πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @huzooka
  • Pipeline finished with Failed
    10 days ago
    Total: 461s
    #507403
  • Pipeline finished with Canceled
    10 days ago
    Total: 149s
    #507417
  • Pipeline finished with Failed
    10 days ago
    Total: 698s
    #507419
  • πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί

    CS and Eslint violations are preexisting imho.
    Asking for a (quick) review and about further tasks.

  • πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί

    I also created a patch which can be applied on Webform 6.2.9; uploading it here if anyone is interested.

  • πŸ‡΅πŸ‡ΉPortugal dxvargas

    I have tested the patch and it fixes the problem for malformed YAML (e.g. "this: is: invalid: YAML").
    This part is good.

    When testing I've initially filled the field "Wrapper custom attributes (YAML)" with just a dummy string "BLABLABLA".
    For this, the patch is not working. There is an error that is only visible in the browser's console:

    TypeError: Unsupported operand types: array + string in Drupal\\webform\\Element\\WebformElementAttributes::validateWebformElementAttributes() (line 185 of modules/contrib/webform/src/Element/WebformElementAttributes.php). call_user_func_array(Array, Array) (Line: 281

    Can we make this dummy proof and also display an error when a random string is filled in these fields?

  • πŸ‡΅πŸ‡ΉPortugal dxvargas
  • πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί
  • Pipeline finished with Failed
    2 days ago
    Total: 473s
    #514100
  • Pipeline finished with Failed
    2 days ago
    Total: 398s
    #514108
  • πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί

    Re #5,
    Thank you for testing this! I also addressed the issue you found, and added it as a test case.

    I'm asking for a second round review.

    Created a patch on top of 6.2.x.

  • πŸ‡΅πŸ‡ΉPortugal dxvargas

    It works flawless! Code and tests are good.
    I mark the issue as RTBC.

  • πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦

    liam morland β†’ made their first commit to this issue’s fork.

Production build 0.71.5 2024