kovetskiy / mark

Sync your markdown files with Confluence pages.
https://samizdat.dev
Apache License 2.0
993 stars 148 forks source link

External ac:image URLs are not escaped properly #305

Closed recrtl closed 1 year ago

recrtl commented 1 year ago

What happened? Confluence is throwing errors when images with multiple query parameters, because & characters are not escaped to & (see https://jira.atlassian.com/browse/CONFSERVER-35200). This is happening since the update that uses ac:image for images https://github.com/kovetskiy/mark/commit/fd97ee70f96d0a63d08297c4d0d1fb8424ebc589 When uploading the markdown file, Confluence complains with a 400 error.

What did you expect to happen? External images URLs are escaped and Confluence accepts them. To do that, this .md line ![My External Image](http://confluence.atlassian.com/images/logo/confluence_48_trans.png?key1=value1&key2=value2) Should be transformed to <p><ac:image ac:alt="My External Image"><ri:url ri:value="http://confluence.atlassian.com/images/logo/confluence_48_trans.png?key1=value1&amp;key2=value2"/></ac:image></p>

How can we reproduce the behavior you experienced? Steps to reproduce the behavior:

  1. Include a .md file with an external image URL with multiple query parameters, e.g. ![My External Image](http://confluence.atlassian.com/images/logo/confluence_48_trans.png?key1=value1&key2=value2)
  2. Run mark and upload to Confluence
  3. Confluence returns a 404

Information (please complete the following information):

Logs or other output

FATAL Confluence API returned unexpected status: 400 Bad Request, output: "{\"statusCode\":400,\"data\":{\"authorized\":false,\"valid\":true,\"allowedInReadOnlyMode\":true,\"errors\":[],\"successful\":false},\"message\":\"Error parsing xhtml: Unexpected character '=' (code 61); expected a semi-colon after the reference for entity 'key2'\\n at [row,col {unknown-source}]: [11,212]\",\"reason\":\"Bad Request\"}"

Additional context N/A

recrtl commented 1 year ago

Proposing fix in PR https://github.com/kovetskiy/mark/pull/306