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

An invalid value of a typed wiki macro parameter is dropped silently instead of failing

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 17.10.0, 18.9.0
    • Rendering - WikiMacro
    • None
    • Unknown

    Description

      When a parameter of a wiki macro declares a type, a value that cannot be converted to that type is dropped without any error. The macro runs as if the parameter was not set, so it renders with its default value and nothing tells the user that the value they typed was wrong.

      Java macros do not behave this way: {{toc scope="foo"/}} fails with "Invalid macro parameters used for the [toc] macro. Cause: [Unable to convert value [foo]. Allowed values are (case insensitive) "LOCAL" or "PAGE".]".

      Steps to reproduce

      1. Edit a page with the wiki editor.
      2. Add A {{mention reference="XWiki.Admin" style="LOGIN"/}} B {{mention reference="XWiki.Admin" style="foo"/}} C.
      3. Save and view the page.

      Expected

      The second mention fails with a message saying that foo is not a valid value of the style parameter, and listing the allowed values, like the toc macro does.

      Actual

      • The first mention renders @Admin.
      • The second one renders @Administrator, the default full name style, with no message.

      Inside the wiki macro, $wikimacro.parameters does not contain the parameter at all: with a test wiki macro declaring a style parameter of type org.xwiki.mentions.DisplayStyle, style="LOGIN" gives a DisplayStyle value, while style="foo" gives an empty $wikimacro.parameters.parameterNames. Only the older $xcontext.macro.params binding still holds foo.

      This affects every typed parameter whose converter rejects invalid values, such as an enum or java.awt.Color. Booleans and numbers are converted leniently instead, which is XCOMMONS-3847.

      Lead

      DefaultWikiMacroRenderer#convertParameters catches the conversion exception and skips the parameter:

      } catch (Exception e) {
          // Impossible to convert this property, skipping it
          // Not logging any error since it's a valid use case in the context of wiki macros
          continue;
      }
      

      The catch was added by XWIKI-16549 in 2019. A parameter type with no converter, such as the one fixed by XWIKI-17768, may still need to be skipped, but a value rejected by an existing converter should give the same error as for a Java macro.

      Impact found on macro fluidity

      The WYSIWYG usability audit of the macros checks that an invalid parameter value produces a message that says what is wrong and how to fix it (criterion E2 of the usability criteria of the proposal WYSIWYG usability of XWiki macros). Because of this behavior, no wiki macro can pass it for a typed parameter: declaring an enum or a color type, which gives a better input in the Edit Macro dialog, turns an invalid value into a silent fallback to the default.

      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: