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

Commit

Permalink
Merge pull request #254 from SamhammerAG/master
Browse files Browse the repository at this point in the history
Fix: Prevent errors when (for unclear reasons) the native `DataTransfer#files` contains `null` values when drag&dropping files into the editor in Chrome.

Thanks to @code-chris!
  • Loading branch information
Reinmar authored Nov 22, 2018
2 parents ebc27e6 + 18b39cf commit 2a45481
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/imageupload/imageuploadediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ export default class ImageUploadEditing extends Plugin {
return;
}

const images = Array.from( data.dataTransfer.files ).filter( isImageType );
const images = Array.from( data.dataTransfer.files ).filter( file => {
if ( !file ) {
return false;
}

return isImageType( file );
} );

const ranges = data.targetRanges.map( viewRange => editor.editing.mapper.toModelRange( viewRange ) );

Expand Down
14 changes: 14 additions & 0 deletions tests/imageupload/imageuploadediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ describe( 'ImageUploadEditing', () => {
expect( getModelData( model ) ).to.equal( '<paragraph>foo[]</paragraph>' );
} );

it( 'should not insert image when file is null', () => {
const viewDocument = editor.editing.view.document;
const dataTransfer = new DataTransfer( { files: [ null ], types: [ 'Files' ] } );

setModelData( model, '<paragraph>foo[]</paragraph>' );

const targetRange = doc.selection.getFirstRange();
const targetViewRange = editor.editing.mapper.toViewRange( targetRange );

viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );

expect( getModelData( model ) ).to.equal( '<paragraph>foo[]</paragraph>' );
} );

it( 'should not insert image when there is non-empty HTML content pasted', () => {
const fileMock = createNativeFileMock();
const dataTransfer = new DataTransfer( {
Expand Down

0 comments on commit 2a45481

Please sign in to comment.