This repository was archived by the owner on Jun 26, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import setDataInElement from '@ckeditor/ckeditor5-utils/src/dom/setdatainelement
1717import mix from '@ckeditor/ckeditor5-utils/src/mix' ;
1818import { isElement } from 'lodash-es' ;
1919import 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 ( ) ;
Original file line number Diff line number Diff 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 , / ^ e d i t o r - s o u r c e - e l e m e n t - a l r e a d y - u s e d / ) ;
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>' ,
You can’t perform that action at this time.
0 commit comments