Project

General

Profile

Actions

Defect #36013

closed

Paste image mixed with other DataTransferItem

Added by Adrien Crivelli about 3 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Category:
Attachments
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected 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.


Files

paste-image-mixed-with-other-data-transfer-items.diff (570 Bytes) paste-image-mixed-with-other-data-transfer-items.diff Adrien Crivelli, 2021-10-19 02:51
0001-Fix-for-36013.patch (1.61 KB) 0001-Fix-for-36013.patch Marius BĂLTEANU, 2022-02-27 15:01
copy_image.png (51.9 KB) copy_image.png Yazan Al aeddin, 2022-03-02 11:26

Related issues

Related to Redmine - Defect #36887: copyImageFromClipboard function failed to generate a unique file nameClosedMarius BĂLTEANU

Actions
Actions #1

Updated by Go MAEDA about 3 years 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?

Actions #2

Updated by Adrien Crivelli about 3 years 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.

Actions #3

Updated by Adrien Crivelli about 3 years ago

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

Actions #4

Updated by Go MAEDA about 3 years 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?

Actions #5

Updated by Adrien Crivelli about 3 years 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 ?

Actions #6

Updated by Go MAEDA about 3 years 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.

Actions #7

Updated by Marius BĂLTEANU over 2 years ago

Adrien, sorry for not including this ticket in the latest releases.

I'm not able to reproduce the issue on my local environment, but I made a patch that switches from clipboardData.items to clipboardData.files and that should fix your issue as well. Can you test it, please?

Actions #8

Updated by Yazan Al aeddin over 2 years ago

Hello
I tested it, it works well, because I had this problem on chromium 95.0.4638.69,
but there is a problem, where there are two forms in the same page,
this problem will not exist if we replace the line (copyImageFromClipboard)
var inputEl = $('input:file.filedrop').first();
by var inputEl = $(this).closest("form").find('input:file.filedrop');

Actions #9

Updated by Adrien Crivelli over 2 years ago

On r21452, without patch, I am no longer able to reproduce the issue. It is likely that my brand new Chrome 99.0.4844.51 somehow fixed it.

So I cannot confirm for sure that the patch would fix the original issue, but I can confirm that with the patch it also works.

Actions #10

Updated by Marius BĂLTEANU over 2 years ago

Yazan Al aeddin wrote:

Hello
I tested it, it works well, because I had this problem on chromium 95.0.4638.69,
but there is a problem, where there are two forms in the same page,
this problem will not exist if we replace the line (copyImageFromClipboard)
var inputEl = $('input:file.filedrop').first();
by var inputEl = $(this).closest("form").find('input:file.filedrop');

Can you open a new issue with the steps to reproduce the problem?

Actions #11

Updated by Marius BĂLTEANU over 2 years ago

Adrien Crivelli wrote:

On r21452, without patch, I am no longer able to reproduce the issue. It is likely that my brand new Chrome 99.0.4844.51 somehow fixed it.

So I cannot confirm for sure that the patch would fix the original issue, but I can confirm that with the patch it also works.

Thanks Adrien! I've committed the change as a refactorization.

Actions #12

Updated by Marius BĂLTEANU over 2 years ago

  • Status changed from New to Resolved
  • Assignee set to Marius BĂLTEANU
  • Resolution set to Fixed
Actions #13

Updated by Marius BĂLTEANU over 2 years ago

  • Status changed from Resolved to Closed
Actions #14

Updated by Go MAEDA over 2 years ago

  • Related to Defect #36887: copyImageFromClipboard function failed to generate a unique file name added
Actions

Also available in: Atom PDF