[Laszlo-checkins] r16781 - in openlaszlo/trunk/WEB-INF/lps/lfc/kernel: dhtml swf swf9

ptw@openlaszlo.org ptw at openlaszlo.org
Thu Jun 24 08:17:31 PDT 2010


Author: ptw
Date: 2010-06-24 08:17:29 -0700 (Thu, 24 Jun 2010)
New Revision: 16781

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzTextSprite.as
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzTextSprite.as
Log:
Change 20100621-ptw-L by ptw at padme.home on 2010-06-21 18:12:12 EDT
    in /Users/ptw/OpenLaszlo/trunk
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: Clean up <text>/pattern validator

Bugs Fixed:
    LPP-9133 On dhtml for inputtext/pattern attribute unicode escape sequences must be done like this \\u0001 whereas on swf8/10 like this \u0001
    LPP-9134 WARNING: LzTextSprite.setPattern argument '[^\x01-\b\v-\f\x0e-\x1f\x7f-\x84\x86-\x9f]*' must be of the form "[...]*"

Technical Reviewer: andre.bargull at udo.edu (pending)
QA Reviewer: max at openlaszlo.org (Message-ID: <4C22B49B.2040302 at openlaszlo.org>)

Details:
    LzTextSprite*:  Don't use RegExp to validate character set pattern
    as /.*/ will fail to match line break characters in the pattern.
    Just use brute force to search for the leading '[' and trailing
    ']*'.  If you don't install the pattern, issue an error, not a
    warning.


Tests:
    Test case from bug report



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js	2010-06-24 14:58:29 UTC (rev 16780)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js	2010-06-24 15:17:29 UTC (rev 16781)
@@ -660,7 +660,7 @@
             if (validChar) {
                 var prevent = false;
                 if (keycode != 13 && sprite.restrict) {
-                    // only printable characters
+                    // only permit characters that match the restrict RegExp
                     prevent = (0 > String.fromCharCode(charcode).search(sprite.restrict));
                 }
                 if (! prevent) {

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js	2010-06-24 14:58:29 UTC (rev 16780)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js	2010-06-24 15:17:29 UTC (rev 16781)
@@ -317,14 +317,23 @@
     this.setText(this.text, true);
 }
 
+/*
+ * @devnote [2010-06-21 ptw] (LPP-9134) The restrict attribute is a
+ * general RegExp specifying the permitted characters, but for
+ * compatibility with Flash, we limit it to a character set in the
+ * form `[...]*`.  If you think using RegExp to check this condition
+ * would be a better idea, see the referenced bug first.
+ */
 LzTextSprite.prototype.setPattern = function ( val ){
     if (val == null || val == "") {
         this.restrict = null;
-    } else if (RegExp("^\\[.*\\]\\*$").test( val )) {
-        // remove "*" from end, always allow CR/LF (for flash compatibility)
+    } else if (val.substring(0,1) == "[" &&
+               val.substring(val.length-2, val.length) == "]*") {
+        // remove "*" from end, always allow CR/LF (for flash
+        // compatibility)q
         this.restrict = RegExp(val.substring(0, val.length - 1) + "|[\\r\\n]", "g");
     } else if ($debug) {
-        Debug.warn('LzTextSprite.setPattern argument %w must be of the form "[...]*"', val);
+        Debug.error('LzTextSprite.setPattern argument %w must be of the form "[...]*"', val);
     }
 }
 

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzTextSprite.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzTextSprite.as	2010-06-24 14:58:29 UTC (rev 16780)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzTextSprite.as	2010-06-24 15:17:29 UTC (rev 16781)
@@ -266,10 +266,10 @@
     if (val == null || val == "") {
         this.__LZtextclip.restrict = null;
     } else if (val.substring(0,1) == "[" &&
-        val.substring(val.length-2, val.length) == "]*") {
-            this.__LZtextclip.restrict = val.substring(1,val.length-2);
+               val.substring(val.length-2, val.length) == "]*") {
+        this.__LZtextclip.restrict = val.substring(1,val.length-2);
     } else {
-        Debug.warn('LzTextSprite.setPattern argument %w must be of the form "[...]*"', val);
+        Debug.error('LzTextSprite.setPattern argument %w must be of the form "[...]*"', val);
     }
 }
 

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzTextSprite.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzTextSprite.as	2010-06-24 14:58:29 UTC (rev 16780)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzTextSprite.as	2010-06-24 15:17:29 UTC (rev 16781)
@@ -747,13 +747,22 @@
     if (this.initted) this.owner._updateSize();
 }
 
+/**
+ * @devnote [2010-06-21 ptw] (LPP-9134) The textfield pattern is just
+ * the permitted character set description, without the enclosing
+ * `[...]*`.  If you think using RegExp to check this condition would
+ * be a better idea, see the referenced bug first.
+ *
+ * @access private
+ */
 function setPattern (val:String) :void {
     if (val == null || val == "") {
         this.textfield.restrict = null;
-    } else if (new RegExp("^\\[.*\\]\\*$").test( val )) {
+    } else if (val.substring(0,1) == "[" &&
+               val.substring(val.length-2, val.length) == "]*") {
         this.textfield.restrict = val.substring(1, val.length - 2);
     } else if ($debug) {
-        Debug.warn('LzTextSprite.setPattern argument %w must be of the form "[...]*"', val);
+        Debug.error('LzTextSprite.setPattern argument %w must be of the form "[...]*"', val);
     }
 }
 



More information about the Laszlo-checkins mailing list