In Page Preview, Macros throw XhtmlParsingException: The XML content could not be parsed errors

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Low
    • None
    • Affects Version/s: 8.3.0
    • Component/s: Content - Page
    • 10
    • Severity 3 - Minor
    • 2

      Issue Summary

      This is reproducible on Data Center: (yes)

      This happens in versions 8.3.0 and above.

      In the execute() method of a macro, the data returned from conversionContext.getEntity().getBodyAsString() can be invalid XML under certain conditions. If the XML is subsequently used in

      • xhtmlContent#updateMacroDefinitions
      • XhtmlContent#handleMacroDefinitions

      then the macro will throw the error

      Error rendering macro 'macro name'
      com.atlassian.confluence.content.render.xhtml.XhtmlParsingException: The XML content could not be parsed. There is a problem at line 1, column 1279. Parser message: Unexpected close tag </p>; expected </img>. at [row,col {unknown-source} ]: [1,1279]
      

      Steps to Reproduce

      1. In a macro's execute() method use xhtmlContent.updateMacroDefinitions() and xhtmlContent.handleMacroDefinitions() with conversionContext.getEntity().getBodyAsString()
      2. Create a page with an image first, and then the macro
      3. Before saving the page, select from the ... menu to Preview the page

      Expected Results

      The output of conversionContext.getEntity().getBodyAsString() will have the image with a closing tag,, e.g.

      ... thumbnail=\"true\" />
      

      The macro can be seen correctly.

      Actual Results

      The output of conversionContext.getEntity().getBodyAsString() will have the image without a closing tag, thus creating an invalid XML block

      <p>
          <img class=\"confluence-embedded-image confluence-thumbnail\" style=\"max-height: 250px;\" title=\"Demonstration Space &gt; null &gt; 20150810_090724.jpg\" draggable=\"false\" src=\"http://localhost:1990/confluence/download/attachments/851969/20150810_090724.jpg?version=1&amp;modificationDate=1708319411860&amp;api=v2\" data-image-src=\"/confluence/download/attachments/851969/20150810_090724.jpg?version=1&amp;modificationDate=1708319411860&amp;api=v2\" data-unresolved-comment-count=\"0\" data-linked-resource-id=\"851970\" data-linked-resource-version=\"1\" data-linked-resource-type=\"attachment\" data-linked-resource-default-alias=\"20150810_090724.jpg\" data-base-url=\"http://localhost:1990/confluence\" data-linked-resource-content-type=\"image/jpeg\" data-linked-resource-container-id=\"851969\" data-linked-resource-container-version=\"1\" data-location=\"Demonstration Space &gt; null &gt; 20150810_090724.jpg\" data-image-height=\"1992\" data-image-width=\"1121\" height=\"250\" thumbnail=\"true\">
          </p>
          <table class=\"wysiwyg-macro\" style=\"background-image: url('http://localhost:1990/confluence/plugins/servlet/confluence/placeholder/macro-heading?definition=e2Vjb2hlbHAtbWFjcm86dGl0bGU9VGl0bGV9&amp;locale=en_GB&amp;version=2'); background-repeat: no-repeat;\" data-macro-name=\"ecohelp-macro\" aria-label=\"ecohelp-macro macro\" data-macro-parameters=\"title=Title\" data-macro-schema-version=\"1\" data-macro-body-type=\"RICH_TEXT\" data-mce-resize=\"false\">
              <tbody>
                  <tr>
                      <td class=\"wysiwyg-macro-body\">
                          <p>Macro Body.</p>
                      </td>
                  </tr>
              </tbody>
          </table>
          <p>
              <br />
          </p> 

      The macro displays the error seen and in the logs we might get (if the exception is thrown)

      cause: com.ctc.wstx.exc.WstxParsingException: Unexpected close tag </p>; expected </img>.
      at [row,col \{unknown-source} ]: [1,1177]
      stacktrace:
      com.atlassian.confluence.content.render.xhtml.StaxUtils.processWrappedWstxExceptionOrTrowMapped(StaxUtils.java:461)
      com.atlassian.confluence.content.render.xhtml.storage.StorageXhtmlTransformer.transform(StorageXhtmlTransformer.java:53)
      com.atlassian.confluence.impl.content.render.xhtml.MacroDefinitionTransformerImpl.handleMacroDefinitions(MacroDefinitionTransformerImpl.java:39)
      com.atlassian.confluence.content.render.xhtml.DefaultXhtmlContent.handleMacroDefinitions(DefaultXhtmlContent.java:166)
      jdk.internal.reflect.GeneratedMethodAccessor1151.invoke(Unknown Source)
      

      Workaround

      Currently there is no known workaround for this behavior. A workaround will be added here when available

            Assignee:
            Unassigned
            Reporter:
            James Richards
            Votes:
            5 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: