Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit f4efd9b

Browse files
authored
Merge pull request #48 from ckeditor/t/35
Fix: [Safari, Edge] The image upload (button) feature will not throw an error anymore when trying to access picked files. The feature should not use `for...of` loop on native `FileList` because Safari and Edge do not support `Symbol.iterator` for it yet. Closes #35.
2 parents fa2c7ad + 4815fd1 commit f4efd9b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/imageuploadbutton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default class ImageUploadButton extends Plugin {
5050
view.bind( 'isEnabled' ).to( command );
5151

5252
view.on( 'done', ( evt, files ) => {
53-
for ( const file of files ) {
53+
for ( const file of Array.from( files ) ) {
5454
const insertAt = findOptimalInsertionPosition( editor.document.selection );
5555

5656
if ( isImageType( file ) ) {

tests/imageuploadbutton.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,19 @@ describe( 'ImageUploadButton', () => {
130130
button.fire( 'done', [ file ] );
131131
sinon.assert.notCalled( executeStub );
132132
} );
133+
134+
it( 'should work even if the FileList does not support iterators', () => {
135+
const executeStub = sinon.stub( editor, 'execute' );
136+
const button = editor.ui.componentFactory.create( 'insertImage' );
137+
const files = {
138+
0: createNativeFileMock(),
139+
length: 1
140+
};
141+
142+
button.fire( 'done', files );
143+
sinon.assert.calledOnce( executeStub );
144+
expect( executeStub.firstCall.args[ 0 ] ).to.equal( 'imageUpload' );
145+
expect( executeStub.firstCall.args[ 1 ].file ).to.equal( files[ 0 ] );
146+
} );
133147
} );
134148

0 commit comments

Comments
 (0)