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

Commit 5e42fcf

Browse files
authoredJul 23, 2019
Merge pull request #55 from ckeditor/t/ckeditor5/746
Other: Introduced a check that prevents sharing source elements between editor instances. See ckeditor/ckeditor5#746.
2 parents 1ed0d00 + 8d139f7 commit 5e42fcf

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed
 

‎src/inlineeditor.js

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import getDataFromElement from '@ckeditor/ckeditor5-utils/src/dom/getdatafromele
1919
import mix from '@ckeditor/ckeditor5-utils/src/mix';
2020
import { isElement } from 'lodash-es';
2121
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
22+
import secureSourceElement from '@ckeditor/ckeditor5-core/src/editor/utils/securesourceelement';
2223

2324
/**
2425
* The {@glink builds/guides/overview#inline-editor inline editor} implementation.
@@ -69,6 +70,7 @@ export default class InlineEditor extends Editor {
6970

7071
if ( isElement( sourceElementOrData ) ) {
7172
this.sourceElement = sourceElementOrData;
73+
secureSourceElement( this );
7274
}
7375

7476
const view = new InlineEditorUIView( this.locale, this.editing.view, this.sourceElement );

‎tests/inlineeditor.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,23 @@ describe( 'InlineEditor', () => {
8383
expect( editor.editing.view.getDomRoot() ).to.equal( editor.ui.element );
8484
} );
8585
} );
86+
87+
// See: https://github.com/ckeditor/ckeditor5/issues/746
88+
it( 'should throw when trying to create the editor using the same source element more than once', done => {
89+
InlineEditor.create( editorElement )
90+
.then(
91+
() => {
92+
expect.fail( 'Inline editor should not initialize on an element already used by other instance.' );
93+
},
94+
err => {
95+
assertCKEditorError( err,
96+
/^editor-source-element-already-used/
97+
);
98+
}
99+
)
100+
.then( done )
101+
.catch( done );
102+
} );
86103
} );
87104

88105
describe( 'create()', () => {
@@ -117,6 +134,9 @@ describe( 'InlineEditor', () => {
117134
} );
118135

119136
it( 'should not require config object', () => {
137+
const editorElement = document.createElement( 'div' );
138+
editorElement.innerHTML = '<p><strong>foo</strong> bar</p>';
139+
120140
// Just being safe with `builtinPlugins` static property.
121141
class CustomInlineEditor extends InlineEditor {}
122142
CustomInlineEditor.builtinPlugins = [ Paragraph, Bold ];
@@ -126,6 +146,9 @@ describe( 'InlineEditor', () => {
126146
expect( newEditor.getData() ).to.equal( '<p><strong>foo</strong> bar</p>' );
127147

128148
return newEditor.destroy();
149+
} )
150+
.then( () => {
151+
editorElement.remove();
129152
} );
130153
} );
131154

@@ -140,13 +163,18 @@ describe( 'InlineEditor', () => {
140163
} );
141164

142165
it( 'initializes with config.initialData', () => {
166+
const editorElement = document.createElement( 'div' );
167+
editorElement.innerHTML = '<p>Hello world!</p>';
168+
143169
return InlineEditor.create( editorElement, {
144170
initialData: '<p>Hello world!</p>',
145171
plugins: [ Paragraph ]
146172
} ).then( editor => {
147173
expect( editor.getData() ).to.equal( '<p>Hello world!</p>' );
148174

149-
editor.destroy();
175+
return editor.destroy();
176+
} ).then( () => {
177+
editorElement.remove();
150178
} );
151179
} );
152180

0 commit comments

Comments
 (0)
This repository has been archived.