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

Creating a link to a new page by selecting text and validating the link dialog produces an empty link target

    XMLWordPrintable

Details

    • Integration
    • Unknown
    • N/A
    • N/A

    Description

      Steps to reproduce

      1. Edit a page with the WYSIWYG editor (CKEditor).
      2. Type some text, e.g. Test.
      3. Select that text and open the link dialog (toolbar button or Ctrl+K).
      4. Leave the Page field untouched and validate the dialog.
      5. Save the page.

      Actual result

      The link has an empty target, so it points to the page itself:

      [[Test>>]]
      

      Nothing warns the user, and the only way out is to edit the wiki source.

      Expected result

      A link to a new page named after the selected text, as before 18.2.0:

      [[Test>>doc:Test.WebHome]]
      

      Cause

      Regression of XWIKI-22508 caused by XWIKI-24119. Confirmed by Marius.

      Until 18.1.x, opening the link dialog with a text selection pre-filled the Page field with a new-page reference computed from the selected text by CKEditor.LinkNameStrategyHelper (getDefaultResourceReference() and setDefaultValue() in xwiki-link/plugin.js, added by XWIKI-22508), so validating the dialog without touching anything created the link to the new page.

      XWIKI-24119 removed that pre-fill, and the field now opens empty:

      setup: function(data) {
        let resourceReference = data.resourceReference;
        if (!resourceReference) {
          // We're probably creating a new link so there's no resource to preselect.
          return;
      

      The empty target is not rejected either, because of a second problem: in xwiki-resource/plugin.js, validate() accepts an empty reference as soon as the resource type declares allowEmptyReference, which the doc type does (in resource/resource.js) - legitimately, since that is what allows anchor-only links such as:

      [[label>>||anchor=Section]]
      

      As a result the mustBeSelected check added by XWIKI-23154 sits in the else if branch and is never reached for an empty field, so the dialog validates silently.

      No functional test covers "select text, open the link dialog, validate", which is why the removal went unnoticed.

      Workaround

      Type the page name in the Page field and select "Create new page..." (or "Create with exact reference...") from the suggestions; typed text alone is discarded by the suggest widget. The page-creation node of the tree picker also works.

      To be decided

      Marius: pre-filling the suggest (preselecting a value based on the link label) is fine, but we need to decide between "Create with exact reference" and "Create new page" (relative to the current location), the two options offered when you type the link label yourself in the suggest input.

      Independently of that choice, the empty-reference validation for the doc type should probably be tightened so that an empty reference is only accepted when an anchor or a query string is set, otherwise this silent self-link stays reachable.

      Attachments

        Issue Links

          Activity

            People

              mflorea Marius Dumitru Florea
              vmassol Vincent Massol
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: