From 8e3694a4d048ae13c93a4315e5df8a981a544e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Wr=C3=B3bel?= Date: Tue, 6 Feb 2018 03:17:14 +0100 Subject: [PATCH] Fix: Added missing parse context in DataController#set(). --- src/controller/datacontroller.js | 2 +- tests/controller/datacontroller.js | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/controller/datacontroller.js b/src/controller/datacontroller.js index 2e606e88f..db807c760 100644 --- a/src/controller/datacontroller.js +++ b/src/controller/datacontroller.js @@ -199,7 +199,7 @@ export default class DataController { writer.removeSelectionAttribute( this.model.document.selection.getAttributeKeys() ); writer.remove( ModelRange.createIn( modelRoot ) ); - writer.insert( this.parse( data ), modelRoot ); + writer.insert( this.parse( data, modelRoot ), modelRoot ); } ); } diff --git a/tests/controller/datacontroller.js b/tests/controller/datacontroller.js index 341a8c71e..f46d2d38f 100644 --- a/tests/controller/datacontroller.js +++ b/tests/controller/datacontroller.js @@ -25,15 +25,18 @@ describe( 'DataController', () => { beforeEach( () => { model = new Model(); + + schema = model.schema; modelDocument = model.document; + modelDocument.createRoot(); - modelDocument.createRoot( '$root', 'title' ); + modelDocument.createRoot( '$title', 'title' ); + + schema.register( '$title', { inheritAllFrom: '$root' } ); htmlDataProcessor = new HtmlDataProcessor(); data = new DataController( model, htmlDataProcessor ); - - schema = model.schema; } ); describe( 'constructor()', () => { @@ -143,7 +146,7 @@ describe( 'DataController', () => { } ); describe( 'set()', () => { - it( 'should set data to root', () => { + it( 'should set data to default main root', () => { schema.extend( '$text', { allowIn: '$root' } ); data.set( 'foo' ); @@ -179,6 +182,17 @@ describe( 'DataController', () => { expect( count( modelDocument.history.getDeltas() ) ).to.equal( 2 ); } ); + it( 'should parse given data before set in a context of correct root', () => { + schema.extend( '$text', { allowIn: '$title', disallowIn: '$root' } ); + data.set( 'foo', 'main' ); + data.set( 'Bar', 'title' ); + + expect( getData( model, { withoutSelection: true, rootName: 'main' } ) ).to.equal( '' ); + expect( getData( model, { withoutSelection: true, rootName: 'title' } ) ).to.equal( 'Bar' ); + + expect( count( modelDocument.history.getDeltas() ) ).to.equal( 2 ); + } ); + // This case was added when order of params was different and it really didn't work. Let's keep it // if anyone will ever try to change this. it( 'should allow setting empty data', () => {