Throw an exception when DocumentFragment gets unbalanced input

Change-Id: Ie891bd7ea4d9e9b1c84e7a0390f1af39c0e55fd4
This commit is contained in:
Catrope 2012-05-10 19:28:37 -07:00
parent 1475100a22
commit 7eeb6c7cac
2 changed files with 16 additions and 1 deletions

View file

@ -115,6 +115,10 @@ ve.dm.DocumentFragment = function( data, parentDocument ) {
children = stack.pop();
currentStack = parentStack;
parentStack = stack[stack.length - 2];
if ( !parentStack ) {
// This can only happen if we got unbalanced data
throw 'Unbalanced input passed to DocumentFragment';
}
// Attach the children to the node
ve.batchSplice( currentNode, 0, 0, children );
}

View file

@ -2,10 +2,21 @@ module( 've.dm.DocumentFragment' );
/* Tests */
test( 'constructor', 114, function() {
test( 'constructor', 115, function() {
var fragment = new ve.dm.DocumentFragment( ve.dm.example.data );
// Test count: ( ( 4 tests x 21 branch nodes ) + ( 3 tests x 10 leaf nodes ) ) = 114
ve.example.nodeTreeEqual( fragment.getDocumentNode(), ve.dm.example.tree );
raises(
function() {
fragment = new ve.dm.DocumentFragment( [
{ 'type': '/paragraph' },
{ 'type': 'paragraph' }
] );
},
/^Unbalanced input passed to DocumentFragment$/,
'unbalanced input causes exception'
);
} );
test( 'getData', 1, function() {