chatterino2
chatterino2 copied to clipboard
Fix incomplete traversal of clipboard data when an image is present resulting in Not an Image error
Current clipboard data traversal incorrectly stops the traversal when URLs are present, alongside with an image.
This fixes using "Copy Image" in Google Chrome sometimes being unable to upload the image and failing with message: "Cannot upload file. . Not an image.". This error happens when an tag has more data to it, than just plain src attribute, the "alt" property seems to be interfering with it, yet when the image is opened directly in a new window, the copy worked fine.
"InsideClipboard" program, which shows the clipboard contents, shows that when the image has the alt tag, an extra item into the clipboard gets added, of type UniformResourceLocatorW (which is an URL, so the code path goes into the hasUrls() part) with the image url as data -> but obviously, the string cannot be converted into image data.
Nothing much in the actual code was changed.
The changes are:
- moved the upload code into two lambdas, one that tries the URLs, and the other is trying it directly from clipboard
- early returns now instead of returning from the function, return from the lambda, and indicate whether an upload succesfully happened
- when upload was unsuccessful (e.g. no image in data, invalid format, or unable to convert, ...), release the uploadMutex_ as was done before
fixes #5157
@Nerixyz I opted to not change the code unless absolutely necessary, so that the logic reasoning could be preserved and just the necessary change for the fix was added.
I could make these changes (or I believe maintainers should have access to my repo).
Your changes are mostly cosmetic and wouldn't add any extra new reasoning or logic paths, so I guess I could do them, should I then?
Your changes are mostly cosmetic and wouldn't add any extra new reasoning or logic paths, so I guess I could do them, should I then?
Imo, only the early-return and the moved comment are somewhat important - the no-else-after-return is really cosmetic (if you use clangd, then it should offer you an option to automatically fix that). The logic-issue and else-if in loop can be marked as resolved (I can't do that 🙃).
with the latest indent change, the git changes are now easier to read
My plan is to look into this PR this weekend