瀏覽代碼

Attributes are copied.

Piotr Jasiun 10 年之前
父節點
當前提交
deb25c1b49
共有 2 個文件被更改,包括 17 次插入1 次删除
  1. 1 1
      packages/ckeditor5-utils/src/document/nodelist.js
  2. 16 0
      packages/ckeditor5-utils/tests/document/node.js

+ 1 - 1
packages/ckeditor5-utils/src/document/nodelist.js

@@ -84,7 +84,7 @@ CKEDITOR.define( [
 					// Text.
 					else if ( node instanceof Text ) {
 						for ( j = 0, nodeLen = node.text.length; j < nodeLen; j++ ) {
-							this._nodes.push( new Character( node.text[ j ], utils.clone( node.attrs ) ) );
+							this._nodes.push( new Character( node.text[ j ], node.attrs ) );
 						}
 					}
 					// String.

+ 16 - 0
packages/ckeditor5-utils/tests/document/node.js

@@ -102,6 +102,22 @@ describe( 'tree', function() {
 	} );
 } );
 
+describe( 'constructor', function() {
+	it( 'should copy attributes, not pass by reference', function() {
+		var Element = modules[ 'document/element' ];
+		var Attribute = modules[ 'document/attribute' ];
+
+		var attrs = [ new Attribute( 'attr', true ) ];
+		var foo = new Element( 'foo', attrs );
+		var bar = new Element( 'bar', attrs );
+
+		foo.removeAttr( 'attr' );
+
+		expect( foo.getAttrCount() ).to.equals( 0 );
+		expect( bar.getAttrCount() ).to.equals( 1 );
+	} );
+} );
+
 describe( 'getAttr', function() {
 	it( 'should be possible to get attribute by key', function() {
 		var Element = modules[ 'document/element' ];