Преглед на файлове

Improved filtering out disallowed attributes on child elements.

Oskar Wróbel преди 6 години
родител
ревизия
55b2fec17d
променени са 2 файла, в които са добавени 28 реда и са изтрити 1 реда
  1. 1 1
      packages/ckeditor5-engine/src/model/schema.js
  2. 27 0
      packages/ckeditor5-engine/tests/model/schema.js

+ 1 - 1
packages/ckeditor5-engine/src/model/schema.js

@@ -732,7 +732,7 @@ export default class Schema {
 	 * @param {module:engine/model/writer~Writer} writer
 	 * @param {module:engine/model/writer~Writer} writer
 	 */
 	 */
 	removeDisallowedAttributes( nodes, writer ) {
 	removeDisallowedAttributes( nodes, writer ) {
-		for ( const node of nodes ) {
+		for ( const node of Array.from( nodes ) ) {
 			for ( const attribute of node.getAttributeKeys() ) {
 			for ( const attribute of node.getAttributeKeys() ) {
 				if ( !this.checkAttribute( node, attribute ) ) {
 				if ( !this.checkAttribute( node, attribute ) ) {
 					writer.removeAttribute( attribute, node );
 					writer.removeAttribute( attribute, node );

+ 27 - 0
packages/ckeditor5-engine/tests/model/schema.js

@@ -1823,6 +1823,33 @@ describe( 'Schema', () => {
 					);
 					);
 			} );
 			} );
 		} );
 		} );
+
+		it( 'should filter out all attributes from descendants that are merged while clearing', () => {
+			schema.addAttributeCheck( ( ctx, attributeName ) => {
+				// Disallow `a` in div>$text.
+				if ( ctx.endsWith( 'div $text' ) && attributeName == 'a' ) {
+					return false;
+				}
+			} );
+
+			const a = new Text( 'a', { a: 1 } );
+			const b = new Text( 'b', { a: 2 } );
+			const c = new Text( 'c', { a: 3 } );
+			const div = new Element( 'div', [], [ a, b, c ] );
+
+			root._appendChild( [ div ] );
+
+			model.change( writer => {
+				schema.removeDisallowedAttributes( [ div ], writer );
+
+				expect( writer.batch.operations ).to.length( 3 );
+				expect( writer.batch.operations[ 0 ] ).to.instanceof( AttributeOperation );
+				expect( writer.batch.operations[ 1 ] ).to.instanceof( AttributeOperation );
+				expect( writer.batch.operations[ 2 ] ).to.instanceof( AttributeOperation );
+
+				expect( getData( model, { withoutSelection: true } ) ).to.equal( '<div>abc</div>' );
+			} );
+		} );
 	} );
 	} );
 
 
 	describe( 'definitions compilation', () => {
 	describe( 'definitions compilation', () => {