Skip to content

Commit

Permalink
Merge pull request #8819 from ckeditor/i/8270
Browse files Browse the repository at this point in the history
Fix (image): Image plugins can be loaded in any order without causing an error. Closes #8270.
  • Loading branch information
niegowski authored Jan 14, 2021
2 parents 1735f22 + 5fc6025 commit 1c7397d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/ckeditor5-image/src/imagestyle/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ export function viewToModelStyleAttribute( styles ) {
const viewFigureElement = data.viewItem;
const modelImageElement = first( data.modelRange.getItems() );

// Check if `imageStyle` attribute is allowed for current element.
if ( !conversionApi.schema.checkAttribute( modelImageElement, 'imageStyle' ) ) {
// Check if `modelImageElement` exists (see: https://github.com/ckeditor/ckeditor5/issues/8270)
// and `imageStyle` attribute is allowed for that element, otherwise stop conversion early.
if ( modelImageElement && !conversionApi.schema.checkAttribute( modelImageElement, 'imageStyle' ) ) {
return;
}

Expand Down
19 changes: 19 additions & 0 deletions packages/ckeditor5-image/tests/imagestyle/imagestyleediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
import ImageResizeEditing from '../../src/imageresize/imageresizeediting';
import ImageStyleEditing from '../../src/imagestyle/imagestyleediting';
import ImageEditing from '../../src/image/imageediting';
import ImageStyleCommand from '../../src/imagestyle/imagestylecommand';
Expand Down Expand Up @@ -249,6 +250,24 @@ describe( 'ImageStyleEditing', () => {
'<figure class="ck-widget image" contenteditable="false"><img src="/assets/sample.png"></img></figure>'
);
} );

// See: https://github.com/ckeditor/ckeditor5/issues/8270.
it( 'should stop conversion when model element is not found', () => {
return VirtualTestEditor
.create( {
plugins: [ ImageEditing, ImageResizeEditing, ImageStyleEditing ]
} )
.then( newEditor => {
editor = newEditor;

expect(
() => editor.setData( '<figure class="image image_resized" style="width:331px;"></figure>' )
).not.to.throw();

// No conversion has been done.
expect( editor.getData() ).to.equal( '' );
} );
} );
} );

describe( 'config', () => {
Expand Down

0 comments on commit 1c7397d

Please sign in to comment.