r113448 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113447‎ | r113448 | r113449 >
Date:01:44, 9 March 2012
Author:catrope
Status:deferred
Tags:
Comment:
Add a check for the length of unwrapOuter, and add a test for each
exception
Modified paths:
  • /trunk/extensions/VisualEditor/modules/ve/dm/nodes/ve.dm.DocumentNode.js (modified) (history)
  • /trunk/extensions/VisualEditor/tests/ve/ve.dm.DocumentNode.test.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/ve/ve.dm.DocumentNode.test.js
@@ -801,7 +801,7 @@
802802 );
803803 } );
804804
805 -test( 've.dm.DocumentNode.prepareWrap', 2, function() {
 805+test( 've.dm.DocumentNode.prepareWrap', 5, function() {
806806 var documentModel = ve.dm.DocumentNode.newFromPlainObject( veTest.obj );
807807
808808 // Test 1
@@ -836,4 +836,31 @@
837837 ],
838838 'prepareWrap unwraps a list'
839839 );
 840+
 841+ // Test 3
 842+ raises(
 843+ function() {
 844+ documentModel.prepareWrap( new ve.Range( 12, 27 ), [ { 'type': 'table' } ], [], [], [] );
 845+ },
 846+ /^Element in unwrapOuter does not match: expected table but found list$/,
 847+ 'prepareWrap checks integrity of unwrapOuter parameter'
 848+ );
 849+
 850+ // Test 4
 851+ raises(
 852+ function() {
 853+ documentModel.prepareWrap( new ve.Range( 12, 27 ), [ { 'type': 'list' } ], [], [ { 'type': 'paragraph' } ], [] );
 854+ },
 855+ /^Element in unwrapEach does not match: expected paragraph but found listItem$/,
 856+ 'prepareWrap checks integrity of unwrapEach parameter'
 857+ );
 858+
 859+ // Test 5
 860+ raises(
 861+ function() {
 862+ documentModel.prepareWrap( new ve.Range( 1, 4 ), [ { 'type': 'listItem' }, { 'type': 'paragraph' } ], [], [], [] );
 863+ },
 864+ /^unwrapOuter is longer than the data preceding the range$/,
 865+ 'prepareWrap checks that unwrapOuter fits before the range'
 866+ );
840867 } );
\ No newline at end of file
Index: trunk/extensions/VisualEditor/modules/ve/dm/nodes/ve.dm.DocumentNode.js
@@ -1159,10 +1159,7 @@
11601160 return closings;
11611161 }
11621162
1163 - // TODO sanity checks:
1164 - // * range.start > unwrapOuter.length
1165 - // * unwraps actually match
1166 - // * result is valid
 1163+ // TODO: we're not checking for nesting validity. prepareInsertion also needs this
11671164
11681165 var tx = new ve.dm.Transaction(), i, j, unwrapOuterData;
11691166 range.normalize();
@@ -1171,6 +1168,8 @@
11721169 // The outer unwrapping takes place *outside*
11731170 // the range, so compensate for that
11741171 tx.pushRetain( range.start - unwrapOuter.length );
 1172+ } else if ( range.start < unwrapOuter.length ) {
 1173+ throw 'unwrapOuter is longer than the data preceding the range';
11751174 }
11761175
11771176 // Replace the opening elements for the outer unwrap&wrap

Status & tagging log