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

Commit c73b045

Browse files
authored
Merge pull request #34 from ckeditor/t/ckeditor5/746
Other: Introduced a check that prevents sharing source elements between editor instances. See ckeditor/ckeditor5#746.
2 parents 24bee4c + cac36b1 commit c73b045

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/decouplededitor.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import setDataInElement from '@ckeditor/ckeditor5-utils/src/dom/setdatainelement
1717
import mix from '@ckeditor/ckeditor5-utils/src/mix';
1818
import { isElement } from 'lodash-es';
1919
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
20+
import secureSourceElement from '@ckeditor/ckeditor5-core/src/editor/utils/securesourceelement';
2021

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

6970
if ( isElement( sourceElementOrData ) ) {
7071
this.sourceElement = sourceElementOrData;
72+
secureSourceElement( this );
7173
}
7274

7375
this.data.processor = new HtmlDataProcessor();

tests/decouplededitor.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,26 @@ describe( 'DecoupledEditor', () => {
125125
} );
126126
} );
127127

128+
// See: https://github.com/ckeditor/ckeditor5/issues/746
129+
it( 'should throw when trying to create the editor using the same source element more than once', done => {
130+
const sourceElement = document.createElement( 'div' );
131+
132+
// eslint-disable-next-line no-new
133+
new DecoupledEditor( sourceElement );
134+
135+
DecoupledEditor.create( sourceElement )
136+
.then(
137+
() => {
138+
expect.fail( 'Decoupled editor should not initialize on an element already used by other instance.' );
139+
},
140+
err => {
141+
assertCKEditorError( err, /^editor-source-element-already-used/ );
142+
}
143+
)
144+
.then( done )
145+
.catch( done );
146+
} );
147+
128148
it( 'throws if initial data is passed in Editor#create and config.initialData is also used', done => {
129149
DecoupledEditor.create( '<p>Hello world!</p>', {
130150
initialData: '<p>I am evil!</p>',

0 commit comments

Comments
 (0)