[prev in list] [next in list] [prev in thread] [next in thread] 

List:       os-sim-commits
Subject:    [Os-sim-commits] os-sim/include/classes Security.inc,1.12,1.13
From:       "Tomas V.V.Cox" <tvvcox () users ! sourceforge ! net>
Date:       2006-04-25 10:42:16
Message-ID: E1FYKzp-0008Bh-B2 () mail ! sourceforge ! net
[Download RAW message or body]

Update of /cvsroot/os-sim/os-sim/include/classes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18544/include/classes

Modified Files:
	Security.inc 
Log Message:
- Fix Optional (OSS_NULLABLE) params were failing under certain cases
- Added more tests

Index: Security.inc
===================================================================
RCS file: /cvsroot/os-sim/os-sim/include/classes/Security.inc,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- Security.inc	25 Apr 2006 09:50:39 -0000	1.12
+++ Security.inc	25 Apr 2006 10:42:14 -0000	1.13
@@ -103,12 +103,13 @@
     array_shift($parms);
     
     // array of params instead of list of params
-    // ej: validVar($foo, array(OSS_DIGIT, OSS_FOO))
+    // ej: ossim_valid($foo, array(OSS_DIGIT, OSS_FOO))
     if (func_num_args() == 2 && is_array($parms[0])) {
         $parms = $parms[0];
     }
     $error_msg = OSS_ERROR;
-    for ($i = 0; $i < count($parms); $i++) {
+    $val_notnull = true; // by default do not allow empty vars
+    for ($i=0; $i < count($parms); $i++) {
         //
         // error:
         //
@@ -122,30 +123,31 @@
             $error_msg = sprintf(_("Error in the '%s' field"), $m[1]);
             unset($parms[$i]);
         }
-    }
-    
-    $val_str = '';
-    $val_notnull = true; // by default do not allow empty vars
-    foreach ($parms as $p) {
         //
-        // rule:
+        // rule: (NULL permitted or not)
         //
-        if (preg_match('/^rule:(.+)$/', $p, $m)) {
-            $vars = explode('.', $m[1]);
-            //
-            // rule:OSS_DIGIT.OSS_LETTER
-            //
-            foreach ($vars as $v) {
-                if ($v == 'OSS_NOTNULL') {
-                    $val_notnull = true;
-                } elseif ($v == 'OSS_NULLABLE') {
-                    $val_notnull = false;
-                } elseif (preg_match('/^OSS_/', $v) && isset($cons[$v])) {
-                    $val_str .= $cons[$v];
-                }
+        if (preg_match('/^rule:(.+)$/', $parms[$i], $m)) {
+            if ($m[1] == 'OSS_NOTNULL') {
+                $val_notnull = true;
+            } elseif ($m[1] == 'OSS_NULLABLE') {
+                $val_notnull = false;
             }
-            continue;
+            unset($parms[$i]);
         }
+    }
+    //
+    // NULL check
+    //
+    if ($subject === null || $subject === '') {
+        if ($val_notnull) {
+            return ossim_set_error("$error_msg ("._("missing required field").")");
+        } else {
+            return true;
+        }
+    }
+    $val_str = '';
+    
+    foreach ($parms as $p) {
         //
         // func:
         //
@@ -176,12 +178,7 @@
         //
         $val_str .= $p;
     }
-    //
-    // NULL Check
-    //
-    if ($val_notnull && ($subject === null || $subject === '')) {
-        return ossim_set_error("$error_msg ("._("missing required field").")");
-    }
+    
     //echo "str: '$val_str' validate: '$subject'\n";
     if ($val_str && preg_match("/[^$val_str]/", $subject, $m)) {
         $not = $m[0];
@@ -293,20 +290,22 @@
 test(ossim_valid('hello', OSS_ALPHA), true); #3
 test(ossim_valid('hello dasd', OSS_ALPHA), false); #4
 test(ossim_valid('', OSS_NOTNULL), false); #5
-test(ossim_valid('hello', OSS_NOTNULL), true); #6
-test(ossim_valid('3', OSS_NOTNULL, OSS_LETTER), false); #7
-test(ossim_valid('hello', OSS_NOTNULL, OSS_LETTER), true); #8
-test(ossim_valid('0.1.1.1', OSS_IP), true); #9
-test(ossim_valid('500.1.1.1', OSS_IP), false); #10
-test(ossim_valid('hello@hello.com', OSS_MAIL), true); #11
-test(ossim_valid('hello@hello', OSS_MAIL), false); #12
-test(ossim_valid('hello@he.llo.', OSS_MAIL), false); #13
-test(ossim_valid('hello@he.llo.9', OSS_MAIL), false); #14
-test(ossim_valid('hello@hello.com9', array(OSS_NOTNULL, OSS_MAIL)), false); #15
-test(ossim_valid('hello@hello.com', array(OSS_NOTNULL, OSS_MAIL)), true); #16
+test(ossim_valid('', OSS_NULLABLE), true); #6
+test(ossim_valid('3', OSS_LETTER), false); #7
+test(ossim_valid('hello', OSS_LETTER), true); #8
+test(ossim_valid('0.1.1.1', OSS_IP_ADDR), true); #9
+test(ossim_valid('500.1.1.1', OSS_IP_ADDR), false); #10
+test(ossim_valid('hello@hello.com', OSS_MAIL_ADDR), true); #11
+test(ossim_valid('hello@hello', OSS_MAIL_ADDR), false); #12
+test(ossim_valid('hello@he.llo.', OSS_MAIL_ADDR), false); #13
+test(ossim_valid('hello@he.llo.9', OSS_MAIL_ADDR), false); #14
+test(ossim_valid('hello@hello.com9', array(OSS_NOTNULL, OSS_MAIL_ADDR)), false); #15
+test(ossim_valid('', array(OSS_NULLABLE, OSS_MAIL_ADDR)), true); #16
 test(ossim_valid('', OSS_LETTER), false); #17
 test(ossim_valid('ho la', OSS_LETTER, OSS_SCORE), false); #18
-
+test(ossim_valid('', OSS_NULLABLE, OSS_IP_ADDR), true); #19
+test(ossim_valid('', OSS_IP_ADDR, OSS_NULLABLE), true); #20
+test(ossim_valid('', OSS_IP_ADDR), false); #21
 
 test(ossim_valid('foo', 'func:no_exists'), true); #should die
 //*/



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Os-sim-commits mailing list
Os-sim-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/os-sim-commits
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic