Przeglądaj źródła

Throw when range to move is invalid.

Oskar Wróbel 8 lat temu
rodzic
commit
ef7d8a6cf1

+ 9 - 0
packages/ckeditor5-engine/src/model/batch.js

@@ -282,6 +282,15 @@ export default class Batch {
 	}
 
 	move( range, itemOrPosition, offset ) {
+		if ( !( range instanceof Range ) ) {
+			/**
+			 * Invalid range to move.
+			 *
+			 * @error batch-move-invalid-range
+			 */
+			throw new CKEditorError( 'batch-move-invalid-range: Invalid range to move.' );
+		}
+
 		if ( !range.isFlat ) {
 			/**
 			 * Range to move is not flat.

+ 6 - 0
packages/ckeditor5-engine/tests/model/batch.js

@@ -1444,6 +1444,12 @@ describe( 'Batch', () => {
 			expect( getNodesAndText( Range.createIn( root.getChild( 1 ) ) ) ).to.equal( 'abcobarxyz' );
 		} );
 
+		it( 'should throw if object to move is not a range', () => {
+			expect( () => {
+				doc.batch().move( root.getChild( 0 ), new Position( root, [ 1, 3 ] ) );
+			} ).to.throw( CKEditorError, /^batch-move-invalid-range/ );
+		} );
+
 		it( 'should throw if given range is not flat', () => {
 			const notFlatRange = new Range( new Position( root, [ 0, 2, 2 ] ), new Position( root, [ 0, 6 ] ) );