atlassian-api / atlassian-python-api

Atlassian Python REST API wrapper
https://atlassian-python-api.readthedocs.io
Apache License 2.0
1.29k stars 642 forks source link

Error in download_attachments_from_page() with some file names #1355

Open Psancs05 opened 3 months ago

Psancs05 commented 3 months ago

Hi!

Using the method download_attachments_from_page() raises an exception when the filename is not sanitize Eg: image2019-9-13 11:51:31.png this file raises an error, I believe that is caused by the colons (:)

gkowalc commented 3 months ago

which instance do you use? DC or cloud (if DC which version). Is it jira or confluence? Also if possible, provide complete error trace.

Psancs05 commented 3 months ago

I think that it is not related to the client. Looking into the code I found this in atlassian/confluence.py:

for attachment in attachments:
  file_name = attachment["title"]
  if not file_name:
      file_name = attachment["id"]  # if the attachment has no title, use attachment_id as a filename

Line 1338, in the download_attachments_from_page() definition. In the code the file name is used exactly as it is defined in Confluence, but some special characters (like colons) can cause an error in the filesystem. I have used a regexp in my local package to sanitize the file name and it seem to solve the problem

gkowalc commented 3 months ago

On macOS host, it seems to be fine. Are you using a Windows host? According to https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file, a colon shouldn't be used for files or directory names. Therefore, I don't think the problem is with the library code. I can add a small comment to the code with a warning.