Project

General

Profile

Defect #44556 » 0001-Show-an-error-when-pasting-an-image-exceeds-the-limi.patch

patch for trunk - Go MAEDA, 2026-09-29 07:58

View differences:

app/assets/javascripts/attachments.js
359 359
      // get input file in the closest form
360 360
      var inputEl = $(this).closest("form").find('input:file.filedrop');
361 361
      handleFileDropEvent.target = e.target;
362
      addFile(inputEl, new File([file], filename, { type: file.type }), true);
362
      if (addFile(inputEl, new File([file], filename, { type: file.type }), true) == null) {
363
        window.alert(inputEl.data('max-number-of-files-message'));
364
        break;
365
      }
363 366
    }
364 367
  }
365 368
}
test/system/issues_test.rb
191 191
    assert_no_selector '.add_attachment', :visible => true
192 192
  end
193 193

  
194
  def test_pasting_image_beyond_max_attachments_at_once_should_show_error
195
    set_tmp_attachments_directory
196
    log_user('jsmith', 'jsmith')
197

  
198
    Redmine::Configuration.with('max_attachments_at_once' => 2) do
199
      visit '/projects/ecookbook/issues/new'
200
    end
201
    paste_image = lambda do
202
      page.execute_script(<<~JS)
203
        // 1x1 1-bit grayscale PNG image
204
        const png = Uint8Array.from(atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVR42mNgAAAAAgAB5Sfe/AAAAABJRU5ErkJggg=='), c => c.charCodeAt(0));
205
        const clipboardData = new DataTransfer();
206
        clipboardData.items.add(new File([png], 'image.png', { type: 'image/png' }));
207
        const event = new Event('paste', { bubbles: true, cancelable: true });
208
        Object.defineProperty(event, 'clipboardData', { value: clipboardData });
209
        document.getElementById('issue_description').dispatchEvent(event);
210
      JS
211
    end
212
    2.times { paste_image.call }
213
    assert_selector '.attachments_fields > span', :count => 2
214
    accept_alert(/maximum number of files that can be attached simultaneously \(2\)/) do
215
      paste_image.call
216
    end
217
    assert_selector '.attachments_fields > span', :count => 2
218
  end
219

  
194 220
  def test_create_issue_with_new_target_version
195 221
    log_user('jsmith', 'jsmith')
196 222

  
(1-1/2)