Add tests for _get_attachment
, and do not use attachment filename for temporary storage
#1553
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes #1551 by using the prefix
"relay_attachment_"
, and not basing the filename prefix or suffix on user data from the attachment filename. It also adds some tests for_get_attachment()
._get_attachment()
uses SpooledTemporaryFile, which holds an attachment in memory until it reaches 150 KiB, when it is stored in a temporary file. Previously, we used the attachment filename to make the prefix and suffix for the temporary file. However, this fails when the attachment filename has invalid characters, such as a colon (:
). Now that we support larger files, we're starting to see some large attachments with a URL for the filename (https://example.com/image.jpg
), and failures when writing to a tempfile with that name, such as:With this change, the temporary file will now have a randomly generated name, not related to the attachment name.
There is another potential bug for attachments with no filename, but I have not seen the signature in production yet, where calling
prefix=os.path.splitext(fn)[0]
results in the error: