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

Merge pull request #714 from ckeditor/t/713

AttributeOperation should use isEqual to check attribute value.
Piotrek Koszuliński преди 9 години
родител
ревизия
1946e97242

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

@@ -110,17 +110,18 @@ export default class AttributeOperation extends Operation {
 	_execute() {
 	_execute() {
 		// Validation.
 		// Validation.
 		for ( let item of this.range.getItems() ) {
 		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.
 				 * Changed node has different attribute value than operation's old attribute value.
 				 *
 				 *
 				 * @error operation-attribute-wrong-old-value
 				 * @error operation-attribute-wrong-old-value
 				 * @param {module:engine/model/item~Item} item
 				 * @param {module:engine/model/item~Item} item
 				 * @param {String} key
 				 * @param {String} key
+				 * @param {*} value
 				 */
 				 */
 				throw new CKEditorError(
 				throw new CKEditorError(
 					'attribute-operation-wrong-old-value: Changed node has different attribute value than operation\'s old attribute value.',
 					'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;
 		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', () => {
 	it( 'should create an AttributeOperation as a reverse', () => {
 		let range = new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) );
 		let range = new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) );
 		let operation = new AttributeOperation( range, 'x', 'old', 'new', doc.version );
 		let operation = new AttributeOperation( range, 'x', 'old', 'new', doc.version );