Ver código fonte

Changed: Cast attribute value to string in `view.Element#setAttribute`.

Szymon Cofalik 8 anos atrás
pai
commit
ecc60ad2c1

+ 2 - 0
packages/ckeditor5-engine/src/view/element.js

@@ -329,6 +329,8 @@ export default class Element extends Node {
 	 * @fires module:engine/view/node~Node#change
 	 */
 	setAttribute( key, value ) {
+		value = String( value );
+
 		this._fireChange( 'attributes', this );
 
 		if ( key == 'class' ) {

+ 6 - 0
packages/ckeditor5-engine/tests/view/element.js

@@ -430,6 +430,12 @@ describe( 'Element', () => {
 				expect( el._attrs.get( 'foo' ) ).to.equal( 'bar' );
 			} );
 
+			it( 'should cast attribute value to a string', () => {
+				el.setAttribute( 'foo', true );
+
+				expect( el._attrs.get( 'foo' ) ).to.equal( 'true' );
+			} );
+
 			it( 'should fire change event with attributes type', done => {
 				el.once( 'change:attributes', eventInfo => {
 					expect( eventInfo.source ).to.equal( el );