Throw an exception when attempting to annotate a closing element

Change-Id: Ifd4e49ee05e74db8bec754a6c1f79c969c1f2eac
This commit is contained in:
Trevor Parscal 2012-06-08 12:20:54 -07:00
parent 5aa6f4b342
commit 5e6713eae5

View file

@ -115,8 +115,12 @@ ve.dm.TransactionProcessor.prototype.applyAnnotations = function( to ) {
for ( var i = this.cursor; i < to; i++ ) {
item = this.document.data[i];
element = item.type !== undefined;
if ( element && ve.dm.nodeFactory.canNodeHaveChildren( item.type ) ) {
throw 'Invalid transaction, can not annotate a branch element';
if ( element ) {
if ( item.type.charAt( 0 ) === '/' ) {
throw 'Invalid transaction, cannot annotate a branch closing element';
} else if ( ve.dm.nodeFactory.canNodeHaveChildren( item.type ) ) {
throw 'Invalid transaction, cannot annotate a branch opening element';
}
}
annotated = element ? 'annotations' in item : ve.isArray( item );
annotations = annotated ? ( element ? item.annotations : item[1] ) : {};