Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-25287

The Edit Macro dialog doesn't enforce the constraints declared on the parameters of Java macros

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Unresolved
    • Major
    • None
    • None
    • Display, WYSIWYG Editor
    • None
    • Unknown

    Description

      Java macros can declare constraints on their parameters with Bean Validation annotations, such as @Min, @Max or @Pattern. These constraints are only checked when the macro is rendered: the parameter descriptor sent to the WYSIWYG editor does not carry them, so the Edit Macro dialog accepts and saves any value.

      For example, the start and depth parameters of the Table of Contents macro declare @Min(1), but their descriptor only has "displayType": "int" and a default value.

      Steps to reproduce

      1. Edit a page with the WYSIWYG editor.
      2. Insert the Table of Contents macro.
      3. Type 0 in the depth parameter and submit.

      Expected

      The field does not accept a value below 1. An invalid value is flagged next to the field and the dialog does not submit until it is fixed.

      Actual

      The dialog submits, and the macro renders "Invalid macro parameters used for the [toc] macro. Cause: [Failed to validate bean: [must be greater than or equal to 1]]", which does not name the parameter.

      Proposal

      • Expose the constraints of a parameter in its descriptor, for example a minimum, a maximum and a pattern.
      • Use them in the edit templates of the Edit Macro dialog, for example the min and max attributes of the number input proposed in XWIKI-25182, so that the browser validation the dialog runs before submitting covers them.

      XWIKI-25197 proposes the same constraints for wiki macro parameters.

      Found while auditing the Table of Contents macro: https://design.xwiki.org/xwiki/bin/view/Proposal/WYSIWYGusabilityofXWikimacros/Macros/toc/

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Lucas C Charpentier Lucas
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: