Author: jmorliaguet
Date: Sun Feb 12 22:12:28 2006
New Revision: 2369

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/ctal.js
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_ctal_test.html
Log:

- more protection against data corruption



Modified: cpsskins/branches/jmo-perspectives/ui/framework/ctal.js
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/ctal.js     (original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/ctal.js     Sun Feb 12 
22:12:28 2006
@@ -152,11 +152,18 @@
       throw e
     }
   }
+
   var parent = tmpl.parentNode;
   if (!parent) return;
   var marker = tmpl.nextSibling;
   parent.removeChild(tmpl);
 
+  // the iterator variable has the same name as the looped through array.
+  if (nmx[0] == nmx[1]) {
+    throw new ctal.TALError(nmx[0] +
+      " iterator variable overwrites loop variable.");
+  }
+
   for (var i=0; i<datas.length; i++) {
     // do a deep copy of the data structure traversed by the repeat loop
     // to avoid corrupting it.

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_ctal_test.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_ctal_test.html
  (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_ctal_test.html
  Sun Feb 12 22:12:28 2006
@@ -293,6 +293,11 @@
 <div id="e33"><p ctal:repeat="a javascript:[1, 2]"><span
                  ctal:content="a">...</span></div>
 
+<!-- the repeat expression is invalid: the local loop variable cannot be the
+     same as the looped through array  -->
+<div id="e34"><p ctal:repeat="f f" ctal:content="f">...</p></div>
+
+
 <!-- Tests follow -->
 <script type="text/javascript">
 // <![CDATA[
@@ -325,7 +330,10 @@
   new Test.Unit.Runner({
 
     setup: function() {
-      ctal.process_ctal(document, data);
+      try {
+        ctal.process_ctal(document, data);
+      } catch (e) {
+      }
     },
 
     testDataStructure: function() { with(this) {
@@ -499,6 +507,7 @@
     testEdgeCases: function() { with(this) {
       assertEqual('', htmlOf("e32"));
       assertEqual('<p><span>1</span></p><p><span>2</span></p>', htmlOf("e33"));
+      assertEqual('', htmlOf("e34"));
     }}
 
   });
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to