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

Commit 8c56dce

Browse files
author
Piotr Jasiun
authored
Merge pull request #1280 from ckeditor/t/1278
Fix: Added missing parse context in `DataController#set()`. Closes #1278.
2 parents b077d6f + 8e3694a commit 8c56dce

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/controller/datacontroller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export default class DataController {
199199
writer.removeSelectionAttribute( this.model.document.selection.getAttributeKeys() );
200200

201201
writer.remove( ModelRange.createIn( modelRoot ) );
202-
writer.insert( this.parse( data ), modelRoot );
202+
writer.insert( this.parse( data, modelRoot ), modelRoot );
203203
} );
204204
}
205205

tests/controller/datacontroller.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ describe( 'DataController', () => {
2525

2626
beforeEach( () => {
2727
model = new Model();
28+
29+
schema = model.schema;
2830
modelDocument = model.document;
31+
2932
modelDocument.createRoot();
30-
modelDocument.createRoot( '$root', 'title' );
33+
modelDocument.createRoot( '$title', 'title' );
34+
35+
schema.register( '$title', { inheritAllFrom: '$root' } );
3136

3237
htmlDataProcessor = new HtmlDataProcessor();
3338

3439
data = new DataController( model, htmlDataProcessor );
35-
36-
schema = model.schema;
3740
} );
3841

3942
describe( 'constructor()', () => {
@@ -143,7 +146,7 @@ describe( 'DataController', () => {
143146
} );
144147

145148
describe( 'set()', () => {
146-
it( 'should set data to root', () => {
149+
it( 'should set data to default main root', () => {
147150
schema.extend( '$text', { allowIn: '$root' } );
148151
data.set( 'foo' );
149152

@@ -179,6 +182,17 @@ describe( 'DataController', () => {
179182
expect( count( modelDocument.history.getDeltas() ) ).to.equal( 2 );
180183
} );
181184

185+
it( 'should parse given data before set in a context of correct root', () => {
186+
schema.extend( '$text', { allowIn: '$title', disallowIn: '$root' } );
187+
data.set( 'foo', 'main' );
188+
data.set( 'Bar', 'title' );
189+
190+
expect( getData( model, { withoutSelection: true, rootName: 'main' } ) ).to.equal( '' );
191+
expect( getData( model, { withoutSelection: true, rootName: 'title' } ) ).to.equal( 'Bar' );
192+
193+
expect( count( modelDocument.history.getDeltas() ) ).to.equal( 2 );
194+
} );
195+
182196
// This case was added when order of params was different and it really didn't work. Let's keep it
183197
// if anyone will ever try to change this.
184198
it( 'should allow setting empty data', () => {

0 commit comments

Comments
 (0)