Pick up replacement file's content_type before regenerating filename - #9261
Open
c-tonneslan wants to merge 1 commit into
Open
Pick up replacement file's content_type before regenerating filename#9261c-tonneslan wants to merge 1 commit into
c-tonneslan wants to merge 1 commit into
Conversation
Replacing a .docx with a .tsv was producing filename .tsv.docx because FoiAttachment#filename= reads the current content_type to figure out which extension to append, and the content_type was still the original. Sync the field from the uploaded replacement file before running filename= so the new extension wins. Updated the existing #replace! 'replaces with file' spec (which was tracking this as a FIXME against mysociety#9016). Closes mysociety#9016 Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #9016.
@garethrees flagged that replacing a
.docxattachment with a.tsvwas ending up as.tsv.docx.FoiAttachment#filename=reads the currentcontent_typeto decide whether to append an extension, but at the pointhandle_replacementscalls it,content_typeis still the original.docxmime, so the new.tsvfilename gets.docxtacked on.Sync
content_typefrom the replacementUploadedFilebefore theself.filename = ...line runs, sofilename=sees the new mime and doesn't try to append the old extension.The existing
#replace!'replacing with file' spec already tracked this as a FIXME pointing at #9016 (expectingredacted.png.txt); flipped that to assert the correctredacted.pngand added a small assertion that the newcontent_typeis the replacement's.