Patch #36013

Paste image mixed with other DataTransferItem

Added by Adrien Crivelli about 1 month ago. Updated 21 days ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Attachments
Target version:-

Description

It's been a few months that my Chrome (now Version 94.0.4606.81) cannot paste image when creating issue (with or without any Chrome extensions). I cannot reproduce with Firefox or not even Chromium. And I cannot pinpoint the reason why this problem started, but it has been consistently reproduced for months now, across multiple Chrome updates.

This is the JS error that occurs:

attachments.js?1591235575:275 Uncaught TypeError: Cannot read properties of null (reading 'name')
    at HTMLDivElement.copyImageFromClipboard (attachments.js?1591235575:275)
    at HTMLDivElement.dispatch (jquery-2.2.4-ui-1.11.0-ujs-5.2.3.js?1581467927:3)
    at HTMLDivElement.r.handle (jquery-2.2.4-ui-1.11.0-ujs-5.2.3.js?1581467927:3)

This is if I console.log(item) before the error occurs, for a single paste event:

DataTransferItem {kind: 'string', type: 'application/x-qt-image'}
DataTransferItem {kind: 'string', type: 'image/bmp'}
DataTransferItem {kind: 'string', type: 'image/cur'}
DataTransferItem {kind: 'string', type: 'image/ico'}
DataTransferItem {kind: 'string', type: 'image/jpeg'}
DataTransferItem {kind: 'string', type: 'image/jpg'}
DataTransferItem {kind: 'string', type: 'image/pbm'}
DataTransferItem {kind: 'string', type: 'image/pgm'}
DataTransferItem {kind: 'file', type: 'image/png'}     <== Only item that makes sense
DataTransferItem {kind: 'string', type: 'image/ppm'}
DataTransferItem {kind: 'string', type: 'image/xbm'}
DataTransferItem {kind: 'string', type: 'image/xpm'}

Attached is the patch to safely fix this. It applies on current git master (8075884bc48deb3b7af94799d6eba943e999dcb2), or svn r21243.

paste-image-mixed-with-other-data-transfer-items.diff Magnifier (570 Bytes) Adrien Crivelli, 2021-10-19 02:51

History

#1 Updated by Go MAEDA about 1 month ago

Could you show the detailed steps to reproduce the issue? I tried with Chome 94.0.4606.81 (macOS) but still cannot reproduce the issue. Does it depend on which application the image data is copied from?

#2 Updated by Adrien Crivelli about 1 month ago

I use XUbuntu 20.04.3, and often take screenshot with https://github.com/flameshot-org/flameshot. The screenshot will go directly to clipboard which is super convenient to paste into Redmine. Unfortunately some colleagues run Ubuntu 20.04 (not XFCE) with Chrome(ium?) and cannot reproduced either. I am afraid that there is something specific in my setup that trigger the issue, but I cannot figure out what it is.

More importantly my screenshot can be pasted fine on github.com, or in Gimp. So it is somehow related to Redmine. And clipboard from Gimp will also not work on Redmine. So we can exclude flameshot as culprit.

Also see the reference there: https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/kind

I am quite confident that my patch will have no side-effect and might help others in the same (unusual?) situation as me.

I could show you a screencast of the whole thing, but I don't think there is anything relevant to see except the JS error I mentioned earlier.

#3 Updated by Adrien Crivelli about 1 month ago

See here: https://i.imgur.com/jV4IiPT.mp4 (I could not upload here because it is slightly too big)

#4 Updated by Go MAEDA 21 days ago

Adrien Crivelli, thank you for your detailed report.

Could you try https://github.com/redmine/redmine/pull/129/files if the patch also fixes the issue in your environment?

#5 Updated by Adrien Crivelli 21 days ago

Yes, https://github.com/redmine/redmine/pull/129/files fixes the issue for me. Thank you for your time.

By the way is GitHub PR a new way to accept contributions ?

#6 Updated by Go MAEDA 21 days ago

Adrien Crivelli wrote:

Yes, https://github.com/redmine/redmine/pull/129/files fixes the issue for me. Thank you for your time.

Thank you for testing the fix. I will commit one of the patches.

By the way is GitHub PR a new way to accept contributions ?

No, the Redmine team does not accept pull requests (see https://github.com/redmine/redmine/blob/master/.github/PULL_REQUEST_TEMPLATE.md) but I just happened to find that pull request.

Also available in: Atom PDF