https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113448
Revision: 113448
Author: catrope
Date: 2012-03-09 01:44:31 +0000 (Fri, 09 Mar 2012)
Log Message:
-----------
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
trunk/extensions/VisualEditor/tests/ve/ve.dm.DocumentNode.test.js
Modified:
trunk/extensions/VisualEditor/modules/ve/dm/nodes/ve.dm.DocumentNode.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/dm/nodes/ve.dm.DocumentNode.js
2012-03-09 01:43:09 UTC (rev 113447)
+++ trunk/extensions/VisualEditor/modules/ve/dm/nodes/ve.dm.DocumentNode.js
2012-03-09 01:44:31 UTC (rev 113448)
@@ -1159,10 +1159,7 @@
return closings;
}
- // TODO sanity checks:
- // * range.start > unwrapOuter.length
- // * unwraps actually match
- // * result is valid
+ // TODO: we're not checking for nesting validity. prepareInsertion also
needs this
var tx = new ve.dm.Transaction(), i, j, unwrapOuterData;
range.normalize();
@@ -1171,6 +1168,8 @@
// The outer unwrapping takes place *outside*
// the range, so compensate for that
tx.pushRetain( range.start - unwrapOuter.length );
+ } else if ( range.start < unwrapOuter.length ) {
+ throw 'unwrapOuter is longer than the data preceding the range';
}
// Replace the opening elements for the outer unwrap&wrap
Modified: trunk/extensions/VisualEditor/tests/ve/ve.dm.DocumentNode.test.js
===================================================================
--- trunk/extensions/VisualEditor/tests/ve/ve.dm.DocumentNode.test.js
2012-03-09 01:43:09 UTC (rev 113447)
+++ trunk/extensions/VisualEditor/tests/ve/ve.dm.DocumentNode.test.js
2012-03-09 01:44:31 UTC (rev 113448)
@@ -801,7 +801,7 @@
);
} );
-test( 've.dm.DocumentNode.prepareWrap', 2, function() {
+test( 've.dm.DocumentNode.prepareWrap', 5, function() {
var documentModel = ve.dm.DocumentNode.newFromPlainObject( veTest.obj );
// Test 1
@@ -836,4 +836,31 @@
],
'prepareWrap unwraps a list'
);
+
+ // Test 3
+ raises(
+ function() {
+ documentModel.prepareWrap( new ve.Range( 12, 27 ), [ {
'type': 'table' } ], [], [], [] );
+ },
+ /^Element in unwrapOuter does not match: expected table but
found list$/,
+ 'prepareWrap checks integrity of unwrapOuter parameter'
+ );
+
+ // Test 4
+ raises(
+ function() {
+ documentModel.prepareWrap( new ve.Range( 12, 27 ), [ {
'type': 'list' } ], [], [ { 'type': 'paragraph' } ], [] );
+ },
+ /^Element in unwrapEach does not match: expected paragraph but
found listItem$/,
+ 'prepareWrap checks integrity of unwrapEach parameter'
+ );
+
+ // Test 5
+ raises(
+ function() {
+ documentModel.prepareWrap( new ve.Range( 1, 4 ), [ {
'type': 'listItem' }, { 'type': 'paragraph' } ], [], [], [] );
+ },
+ /^unwrapOuter is longer than the data preceding the range$/,
+ 'prepareWrap checks that unwrapOuter fits before the range'
+ );
} );
\ No newline at end of file
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs