Ver código fonte

Fixed: AttributeOperation should use isEqual to check attribute value.

Szymon Cofalik 9 anos atrás
pai
commit
187b1ec906

+ 2 - 2
packages/ckeditor5-engine/src/model/operation/attributeoperation.js

@@ -110,7 +110,7 @@ export default class AttributeOperation extends Operation {
 	_execute() {
 		// Validation.
 		for ( let item of this.range.getItems() ) {
-			if ( this.oldValue !== null && item.getAttribute( this.key ) !== this.oldValue ) {
+			if ( this.oldValue !== null && !isEqual( item.getAttribute( this.key ), this.oldValue ) ) {
 				/**
 				 * Changed node has different attribute value than operation's old attribute value.
 				 *
@@ -120,7 +120,7 @@ export default class AttributeOperation extends Operation {
 				 */
 				throw new CKEditorError(
 					'attribute-operation-wrong-old-value: Changed node has different attribute value than operation\'s old attribute value.',
-					{ item: item, key: this.key }
+					{ item: item, key: this.key, value: this.oldValue }
 				);
 			}
 

+ 16 - 0
packages/ckeditor5-engine/tests/model/operation/attributeoperation.js

@@ -165,6 +165,22 @@ describe( 'AttributeOperation', () => {
 		expect( root.getChild( 0 ).hasAttribute( 'bar' ) ).to.be.true;
 	} );
 
+	it( 'should not throw for non-primitive attribute values', () => {
+		root.insertChildren( 0, new Text( 'x', { foo: [ 'bar', 'xyz' ] } ) );
+
+		expect( () => {
+			doc.applyOperation( wrapInDelta(
+				new AttributeOperation(
+					new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
+					'foo',
+					[ 'bar', 'xyz' ],
+					true,
+					doc.version
+				)
+			) );
+		} ).to.not.throw( Error );
+	} );
+
 	it( 'should create an AttributeOperation as a reverse', () => {
 		let range = new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) );
 		let operation = new AttributeOperation( range, 'x', 'old', 'new', doc.version );