[pLog-svn] r6278 - in plog/branches/lifetype-1.2/class: data/validator misc test/tests/misc

mark at devel.lifetype.net mark at devel.lifetype.net
Sat Mar 29 14:16:35 EDT 2008


Author: mark
Date: 2008-03-29 14:16:35 -0400 (Sat, 29 Mar 2008)
New Revision: 6278

Modified:
   plog/branches/lifetype-1.2/class/data/validator/uploadvalidator.class.php
   plog/branches/lifetype-1.2/class/misc/glob.class.php
   plog/branches/lifetype-1.2/class/misc/integritychecker.class.php
   plog/branches/lifetype-1.2/class/test/tests/misc/glob_test.class.php
Log:
1. Add $casesensitive option to Glob::fnmatch(), the default is false
2. replace Glob::myFnMatch() to Glob::fnmatch() in all class file to help us control the flag easier.

As long as developer use our own Glob::fnmatch(), we can guarantee it perform the same behavior.

Modified: plog/branches/lifetype-1.2/class/data/validator/uploadvalidator.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/validator/uploadvalidator.class.php	2008-03-29 17:56:24 UTC (rev 6277)
+++ plog/branches/lifetype-1.2/class/data/validator/uploadvalidator.class.php	2008-03-29 18:16:35 UTC (rev 6278)
@@ -81,7 +81,7 @@
             // check if the filename extension is forbidden or not
             $fileName = basename($upload->getFileName());
             foreach( explode( " ", $forbiddenFilesStr ) as $file ) {
-            	if( Glob::myFnmatch( $file, $fileName )) {
+            	if( Glob::fnmatch( $file, $fileName )) {
                 	return UPLOAD_VALIDATOR_ERROR_FORBIDDEN_EXTENSION;
                 }
             }
@@ -99,7 +99,7 @@
             // check if the filename extension is one of the allowed ones or not
             $fileName = basename($upload->getFileName());
             foreach( explode( " ", $allowedFilesStr ) as $file ) {
-            	if( Glob::myFnmatch( $file, $fileName )) {
+            	if( Glob::fnmatch( $file, $fileName )) {
 //					print("it's a valid file!");
                 	return true;
                 }

Modified: plog/branches/lifetype-1.2/class/misc/glob.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/misc/glob.class.php	2008-03-29 17:56:24 UTC (rev 6277)
+++ plog/branches/lifetype-1.2/class/misc/glob.class.php	2008-03-29 18:16:35 UTC (rev 6278)
@@ -68,8 +68,13 @@
          * @return True if the file matches the pattern or false if not.
          * @static
          */
-        function fnmatch( $pattern, $file )
+        function fnmatch( $pattern, $file, $casesensitive = false )
         {
+        	if( !$casesensitive ){
+        		$pattern = strtolower( $pattern );
+        		$file = strtolower( $file );
+        	}
+        	
         	if( function_exists("fnmatch")) {
             	// use the native fnmatch version
                 return fnmatch( $pattern, $file );

Modified: plog/branches/lifetype-1.2/class/misc/integritychecker.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/misc/integritychecker.class.php	2008-03-29 17:56:24 UTC (rev 6277)
+++ plog/branches/lifetype-1.2/class/misc/integritychecker.class.php	2008-03-29 18:16:35 UTC (rev 6278)
@@ -84,7 +84,7 @@
 			
 			$result = false;
 			foreach( $ignore as $pattern ) {
-				if( Glob::myFnMatch( $pattern, $file )) {
+				if( Glob::fnmatch( $pattern, $file )) {
 					$result = true;
 					break;					
 				}

Modified: plog/branches/lifetype-1.2/class/test/tests/misc/glob_test.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/test/tests/misc/glob_test.class.php	2008-03-29 17:56:24 UTC (rev 6277)
+++ plog/branches/lifetype-1.2/class/test/tests/misc/glob_test.class.php	2008-03-29 18:16:35 UTC (rev 6278)
@@ -13,10 +13,19 @@
 		function testmyFnMatch()
 		{
 			// incorrect match
-			$this->assertFalse( Glob::myFnMatch( "*.index.template.*", "index.template.php" ));
-			
+			$this->assertFalse( Glob::myFnMatch( "*.index.template.*", "index.template.php" ) );
+
 			// valid match
-			$this->assertTrue( Glob::myFnMatch( "*index.template.*", "index.template.php" ));			
+			$this->assertTrue( Glob::myFnMatch( "*index.template.*", "index.template.php" ) );		
+		}
+
+		function testfnmatch()
+		{
+			// incorrect match
+			$this->assertFalse( Glob::fnmatch( "*index.template.PHP", "index.template.php", true ) );
+
+			// valid match
+			$this->assertTrue( Glob::fnmatch( "*index.template.PHP", "index.template.php" ) );
 		}		
 	}
 ?>
\ No newline at end of file



More information about the pLog-svn mailing list