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

fix: handle null file types in image check #254

Merged
merged 2 commits into from
Nov 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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