8
0
Pārlūkot izejas kodu

Introduced a check that prevents creating the editor using the same element more than once.

Kamil Piechaczek 6 gadi atpakaļ
vecāks
revīzija
8377721677

+ 3 - 0
packages/ckeditor5-editor-decoupled/src/decouplededitor.js

@@ -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.
@@ -76,6 +77,8 @@ export default class DecoupledEditor extends Editor {
 
 		const view = new DecoupledEditorUIView( this.locale, this.editing.view, this.sourceElement );
 		this.ui = new DecoupledEditorUI( this, view );
+
+		secureSourceElement( this );
 	}
 
 	/**

+ 15 - 0
packages/ckeditor5-editor-decoupled/tests/decouplededitor.js

@@ -22,6 +22,7 @@ import log from '@ckeditor/ckeditor5-utils/src/log';
 
 import { describeMemoryUsage, testMemoryUsage } from '@ckeditor/ckeditor5-core/tests/_utils/memory';
 import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
+import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 const editorData = '<p><strong>foo</strong> bar</p>';
 
@@ -125,6 +126,20 @@ 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', () => {
+			const sourceElement = document.createElement( 'div' );
+
+			return DecoupledEditor.create( sourceElement )
+				.then( editor => {
+					expect( () => {
+						new DecoupledEditor( sourceElement ); // eslint-disable-line no-new
+					} ).to.throw( CKEditorError, /^securesourceelement-source-element-used-more-than-once/ );
+
+					return editor.destroy();
+				} );
+		} );
+
 		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>',