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 #34 from ckeditor/t/ckeditor5/746
Browse files Browse the repository at this point in the history
Other: Introduced a check that prevents sharing source elements between editor instances. See ckeditor/ckeditor5#746.
  • Loading branch information
jodator authored Jul 23, 2019
2 parents 24bee4c + cac36b1 commit c73b045
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/decouplededitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import setDataInElement from '@ckeditor/ckeditor5-utils/src/dom/setdatainelement
import mix from '@ckeditor/ckeditor5-utils/src/mix';
import { isElement } from 'lodash-es';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import secureSourceElement from '@ckeditor/ckeditor5-core/src/editor/utils/securesourceelement';

/**
* The {@glink builds/guides/overview#document-editor decoupled editor} implementation.
Expand Down Expand Up @@ -68,6 +69,7 @@ export default class DecoupledEditor extends Editor {

if ( isElement( sourceElementOrData ) ) {
this.sourceElement = sourceElementOrData;
secureSourceElement( this );
}

this.data.processor = new HtmlDataProcessor();
Expand Down
20 changes: 20 additions & 0 deletions tests/decouplededitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,26 @@ describe( 'DecoupledEditor', () => {
} );
} );

// See: https://github.com/ckeditor/ckeditor5/issues/746
it( 'should throw when trying to create the editor using the same source element more than once', done => {
const sourceElement = document.createElement( 'div' );

// eslint-disable-next-line no-new
new DecoupledEditor( sourceElement );

DecoupledEditor.create( sourceElement )
.then(
() => {
expect.fail( 'Decoupled editor should not initialize on an element already used by other instance.' );
},
err => {
assertCKEditorError( err, /^editor-source-element-already-used/ );
}
)
.then( done )
.catch( done );
} );

it( 'throws if initial data is passed in Editor#create and config.initialData is also used', done => {
DecoupledEditor.create( '<p>Hello world!</p>', {
initialData: '<p>I am evil!</p>',
Expand Down

0 comments on commit c73b045

Please sign in to comment.