Pages created via REST with empty paragraph tags are parsed differently in View mode and Edit mode

XMLWordPrintable

    • 2
    • Severity 3 - Minor
    • 1

      Issue Summary

      If a page is created via the REST API rest/api/content/ and its content contain empty paragraph tags, the page will not have any line breaks when viewing. However when the page is open for editing and closed even without any change, paragraphs with a line break, <p><br /></p>, are inserted to the storage format in place of the empty paragraph tags.
      This means a different behaviour between first Viewing a page and after first Editing a page.

      As it is specified for the paragraph <p> tag:

      The <p> tag defines a paragraph of text. It is a block-level element and always starts on a new line.

      So the empty paragraph tags should already be replaced with <p><br /></p> when page is created from the REST API.

      Examples of empty paragraph tags:

      • <p></p>
      • <p />
      • <p> (any number of whitespaces) </p>
      • <p><span></span></p>
      • <p class="(a class name)"></p>
      • <p class="(a class name)" />

      Steps to Reproduce

      1. Create a page via REST API using the example:
        curl -u admin:admin -X POST -H 'Content-Type: application/json' -d '{"type":"page","title":"3 lines with empty paragraphs","space":{"key":"TST"},"body":{"storage":{"value":"<p>These three lines</p><p>      </p><p>should have no space</p><p /><p>between them</p>","representation":"storage"}}}' http://localhost:8080/confluence/rest/api/content/
         
      1. Open the page in Confluence;
      2. Edit the page but don't make any change;
      3. Click on Update.

      Expected Results

      The page should be displayed the same in Step 2 and after Step 4.

      Actual Results

      The page is displayed with no empty lines in Step 2, as seen in

      The storage format for page's v1 is:

      <p>These three lines</p>
      <p>      </p>
      <p>should have no space</p> 
      <p>between them</p>
      

       

      After Step 4 the page is displayed with empty lines in between, as seen in

      The storage format for current version is:

      <p>These three lines</p>
      <p><br /></p>
      <p>should have no space</p>
      <p><br /></p>
      <p>between them</p>
      

      Workaround

      Currently there is no other workaround to prevent this behaviour, except not having empty paragraph tags (any variation) in the content passed to the REST API.

      After adding pages via the REST API, you can run SQL statements to replace the empty paragraphs with either:

      • a whitespace - this will prevent the empty lines to be added after editing;
      • with the tags <p><br /></p> - this replicates the Editor behaviour and is the ideal option as an paragraph tag should always mean a new line.

      Below you'll find SQL statements for the example page given above:

      UPDATE bodycontent SET body = REPLACE(body,'<p>      </p>'),' ') WHERE body LIKE concat('%<p>      </p>%');
      
      UPDATE bodycontent SET body = REPLACE(body,'<p />','<p><br /></p>') WHERE body LIKE '%<p />%';
      

        1. 3-Lines-v1.png
          66 kB
          Bruno Costa
        2. 3-Lines-v2.png
          68 kB
          Bruno Costa

            Assignee:
            Unassigned
            Reporter:
            Bruno Costa (Inactive)
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: