media: use the override suffix when finding an available file name - #3700
Merged
pbek merged 2 commits intoAug 17, 2026
Merged
Conversation
findAvailableFileName declared an overrideSuffix parameter but never read it, so the name always kept the suffix of the input path. Both call sites pass a mime-detected suffix precisely because the input is a temporary file, so pasted media could be saved with no extension.
Owner
|
Is there an open issue (which I can reproduce) this PR is attempting to fix? If not, can you please open one? |
Contributor
Author
|
No open issue, so I opened #3701 with the repro. It boils down to |
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
Owner
|
Thank you! |
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.
Summary
Utils::Misc::findAvailableFileName()declares anoverrideSuffixparameter (misc.h:151) but never reads it, so the returned name always keeps the suffix of the input path.Both call sites in
src/entities/note.cpppass a suffix they detected from the file's mime type, precisely because the input is a temporary file whose name has no suffix or the wrong one. So pasted or imported media can be saved asqownnotes-media-AbCdEfwith no extension, or keep a.jpegthe mime type says should be.jpg.Repro
The fix
Use
overrideSuffixwhen it is not empty, otherwise the suffix of the path. This matchesmakeFileNameRandom(), which has the same parameter and already honours it.Verification
testFindAvailableFileNameOverrideSuffixcovers the two cases above, the unchanged behaviour when no override is given, and the collision counter keeping the override (imageplus an existingimage.pnggivesimage-1.png). RevertingnewSuffixtofileInfo.suffix()fails it on the first comparison.Full unit test target passes: 45, 3, 3, 5, 9, 2, 8 and 36 across the eight test classes,
[Tests PASS].Checklist
main, from a separate branchWritten with AI assistance (Claude Code). I built the test target against Qt 5.15.2 and ran the suite and the mutation check myself.