Uploaded image for project: 'Confluence Cloud'
  1. Confluence Cloud
  2. CONFCLOUD-77723

Attachment using the ampersand character in the File name uses the wrong encoding on the REST/API

XMLWordPrintable

      Issue Summary

      If the file name contains an "&"  (ampersand) in the file name, 
      while the attachment does use the correct URL encoding (%26) and can be downloaded without issues,
      the Confluence V2 Get page by id API returns an incorrect URL to the attachment, using HTML encoding (& a m p
      Trying to use this URL to download the files fails with HTTP error 400.

      Although our documentation at https://support.atlassian.com/confluence-cloud/docs/upload-a-file/#Accepted-file-types-and-size states that we should not use special characters, there is nothing that blocks users from using them on the files uploaded:

      Avoid using special characters in page or attachment names, as the page or attachment may not be found by Confluence search and may cause some Confluence functions to behave unexpectedly.

      This is reproducible on Data Center: (yes) / (no)

      Steps to Reproduce

      1. Attach one image "john&mary.jpg" and a text file "john&mary.txt" to a page;
      2. Publish the page, and reach the top-right "..." > Attachments > Files
      3. Copy the file link of the files. Observe that it is using the URL encoding %26. It is possible to download the files using these links:

      https://xxxx.atlassian.net/wiki/download/attachments/29851685/John%26Mary.jpg?api=v2 
      https://xxxx.atlassian.net/wiki/download/attachments/29851685/john%26mary.txt?api=v2
      

      4. Use the REST/API to get the content of the page

      USER_NAME=_youruser_ ### You must be either a Space Administrator or a Confluence Administrator since we will purge the trash
      USER_PASSWORD=_APItoken_
      CONFLUENCE_BASEURL=https://xxxx.atlassian.net/wiki ### FQDN and context path without the trailing slash
      PAGEID=29851685
      
      curl --request GET \
        --url ${CONFLUENCE_BASEURL}'/api/v2/pages/'${PAGEID}'?body-format=export_view' \
        --user ${USER_NAME}:${USER_PASSWORD} \
        --header 'Accept: application/json' \
        --header 'Content-Type: application/json' 
      

      Expected Results

      The files location returned by the REST/API should be correct:

      • The URL should be the same returned when using the Attachments UI.
      • We should be able to use this URL to download the Attachments.

      Actual Results

      The REST/API returns the following result:

      ...
      <img class=\"confluence-embedded-image image-center\" width=\"360\" src=\"https://xxxx.atlassian.net/wiki/download/attachments/29851685/John&amp;Mary.jpg?api=v2\"></span><p class=\"media-group\">
      
      <a href=\"/wiki/spaces/~5d00b8b192e6c70c5349a042/pages/29851685/test+ampersand?preview=%2F29851685%2F29818973%2Fjohn%26mary.txt\">
      ...
      

      The file name is incorrect due to the encoding. Instead of using the URL encoding as %26, it is using the HTML encoding "& a m p ;"
      Trying to download this link returns HTTP Error 400.

      Workaround

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

              Unassigned Unassigned
              imurakami@atlassian.com Murakami [Atlassian Support]
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: