mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
Throw an exception when DocumentFragment gets unbalanced input
Change-Id: Ie891bd7ea4d9e9b1c84e7a0390f1af39c0e55fd4
This commit is contained in:
parent
1475100a22
commit
7eeb6c7cac
|
@ -115,6 +115,10 @@ ve.dm.DocumentFragment = function( data, parentDocument ) {
|
||||||
children = stack.pop();
|
children = stack.pop();
|
||||||
currentStack = parentStack;
|
currentStack = parentStack;
|
||||||
parentStack = stack[stack.length - 2];
|
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
|
// Attach the children to the node
|
||||||
ve.batchSplice( currentNode, 0, 0, children );
|
ve.batchSplice( currentNode, 0, 0, children );
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,21 @@ module( 've.dm.DocumentFragment' );
|
||||||
|
|
||||||
/* Tests */
|
/* Tests */
|
||||||
|
|
||||||
test( 'constructor', 114, function() {
|
test( 'constructor', 115, function() {
|
||||||
var fragment = new ve.dm.DocumentFragment( ve.dm.example.data );
|
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
|
// Test count: ( ( 4 tests x 21 branch nodes ) + ( 3 tests x 10 leaf nodes ) ) = 114
|
||||||
ve.example.nodeTreeEqual( fragment.getDocumentNode(), ve.dm.example.tree );
|
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() {
|
test( 'getData', 1, function() {
|
||||||
|
|
Loading…
Reference in a new issue