diff --git a/src/imageuploadbutton.js b/src/imageuploadbutton.js index 132819d..1c39d40 100644 --- a/src/imageuploadbutton.js +++ b/src/imageuploadbutton.js @@ -50,7 +50,7 @@ export default class ImageUploadButton extends Plugin { view.bind( 'isEnabled' ).to( command ); view.on( 'done', ( evt, files ) => { - for ( const file of files ) { + for ( const file of Array.from( files ) ) { const insertAt = findOptimalInsertionPosition( editor.document.selection ); if ( isImageType( file ) ) { diff --git a/tests/imageuploadbutton.js b/tests/imageuploadbutton.js index 48e3094..0df4a5f 100644 --- a/tests/imageuploadbutton.js +++ b/tests/imageuploadbutton.js @@ -130,5 +130,19 @@ describe( 'ImageUploadButton', () => { button.fire( 'done', [ file ] ); sinon.assert.notCalled( executeStub ); } ); + + it( 'should work even if the FileList does not support iterators', () => { + const executeStub = sinon.stub( editor, 'execute' ); + const button = editor.ui.componentFactory.create( 'insertImage' ); + const files = { + 0: createNativeFileMock(), + length: 1 + }; + + button.fire( 'done', files ); + sinon.assert.calledOnce( executeStub ); + expect( executeStub.firstCall.args[ 0 ] ).to.equal( 'imageUpload' ); + expect( executeStub.firstCall.args[ 1 ].file ).to.equal( files[ 0 ] ); + } ); } );