This issue has been created
 
 
XWiki Platform / cid:jira-generated-image-avatar-c1db1567-0f64-4bd9-bd53-2ccfacc96190 XWIKI-25287 Open

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

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-052d6f92-51fd-4a64-a7c5-f2e272495528 Charpentier Lucas created this issue on 14/Oct/26 10:13
 
Summary: The Edit Macro dialog doesn't enforce the constraints declared on the parameters of Java macros
Issue Type: cid:jira-generated-image-avatar-c1db1567-0f64-4bd9-bd53-2ccfacc96190 Improvement
Assignee: Unassigned
Components: Display, WYSIWYG Editor
Created: 14/Oct/26 10:13
Priority: cid:jira-generated-image-static-major-ebdd4133-12cf-46a6-8a22-7a074ec8965b Major
Reporter: Charpentier Lucas
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/