Wrong attachment is referenced by <ac:image> in export view

In the export view of a static macro (or a renderMode of a dynamic macro), there is a bug that causes wrong URLs when referencing an attachment on a content object referenced by ID.

On a page with the ID 111, I include a static macro that has the following output: <ac:image><ri:attachment ri:filename="image.png"><ri:content-entity ri:content-id="222"/></ri:attachment></ac:image>. The content ID 222 in this case refers to a custom content object where the image is attached.

When viewing the page in Confluence, the image output by the macro is correctly rendered and includes the image from <baseUrl>/download/attachments/222/image.png?api=v2. However, in the export view, the image is incorrectly rendered from <baseUrl>/download/attachments/111/image.png?api=v2 (using the URL of the the page containing the macro rather than the referenced content object). This leads to the image not being found (or another image being shown in case there happens to be an attachment with the same filename on the current page).

2 Likes