[BUGFIX] Warnings in BE when using "Find filename"
authorDmitry Dulepov <dmitry@typo3.org>
Wed, 23 Nov 2011 13:14:58 +0000 (15:14 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 28 Jan 2012 12:00:43 +0000 (13:00 +0100)
When using "Tools">"DB Check">"Find filename" with a slash
character (for example, "</title>"), there are warnings about
wrong regular expression in the Backend and nothing is found.

Change-Id: I4717ccc8fe3ee2f1e10e121cd86d86f3495f0af4
Resolves: #21591
Releases: 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/8638
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/lowlevel/dbint/index.php

index c8cbf4c..7998bfd 100755 (executable)
 
 
 unset($MCONF);
-require ('conf.php');
-require ($BACK_PATH.'init.php');
-require ($BACK_PATH.'template.php');
+require('conf.php');
+require($BACK_PATH . 'init.php');
+require($BACK_PATH . 'template.php');
 
 $GLOBALS['LANG']->includeLLFile('EXT:lowlevel/dbint/locallang.xml');
-$BE_USER->modAccess($MCONF,1);
+$BE_USER->modAccess($MCONF, 1);
 
 
 
@@ -612,49 +612,53 @@ class SC_mod_tools_dbint_index {
        /**
         * Searching for filename pattern recursively in the specified dir.
         *
-        * @param       string          Base directory
-        * @param       string          Match pattern
-        * @param       array           Array of matching files, passed by reference
-        * @param       integer         Depth to recurse
-        * @return      array           Array with various information about the search result
+        * @param string $basedir: Base directory
+        * @param string $pattern: Match pattern
+        * @param array $matching_files: Array of matching files, passed by reference
+        * @param integer $depth: Depth to recurse
+        * @return array Array with various information about the search result
         * @see func_filesearch()
         */
-       function findFile($basedir,$pattern,&$matching_files,$depth)    {
-               $files_searched=0;
-               $dirs_searched=0;
-               $dirs_error=0;
+       function findFile($basedir, $pattern, &$matching_files, $depth) {
+               $files_searched = 0;
+               $dirs_searched = 0;
+               $dirs_error = 0;
 
                        // Traverse files:
-               $files = t3lib_div::getFilesInDir($basedir,'',1);
-               if (is_array($files))   {
-                       $files_searched+=count($files);
+               $files = t3lib_div::getFilesInDir($basedir, '', 1);
+               if (is_array($files)) {
+                       $files_searched += count($files);
+                               // Escape the regexp. Note: we cannot use preg_quote here because it will escape more than we need!
+                       $regExpPattern = str_replace('/', '\\/', $pattern);
                        foreach ($files as $value) {
-                               if (preg_match('/'.$pattern.'/i',basename($value)))     $matching_files[]=substr($value,strlen(PATH_site));
+                               if (preg_match('/' . $regExpPattern . '/i', basename($value))) {
+                                       $matching_files[] = substr($value, strlen(PATH_site));
+                               }
                        }
                }
 
-
                        // Traverse subdirs
-               if ($depth>0)   {
+               if ($depth > 0) {
                        $dirs = t3lib_div::get_dirs($basedir);
-                       if (is_array($dirs))    {
-                               $dirs_searched+=count($dirs);
+                       if (is_array($dirs)) {
+                               $dirs_searched += count($dirs);
 
                                foreach ($dirs as $value) {
-                                       $inf= $this->findFile($basedir.$value.'/',$pattern,$matching_files,$depth-1);
-                                       $dirs_searched+=$inf[0];
-                                       $files_searched+=$inf[1];
-                                       $dirs_error=$inf[2];
+                                       $inf = $this->findFile($basedir . $value . '/', $pattern, $matching_files, $depth-1);
+                                       $dirs_searched += $inf[0];
+                                       $files_searched += $inf[1];
+                                       $dirs_error = $inf[2];
                                }
                        }
                } else {
                        $dirs = t3lib_div::get_dirs($basedir);
-                       if (is_array($dirs) && count($dirs))    {
-                               $dirs_error=1;  // Means error - there were further subdirs!
+                       if (is_array($dirs) && count($dirs)) {
+                                       // Means error - there were further subdirs!
+                               $dirs_error = 1;
                        }
                }
 
-               return array($dirs_searched,$files_searched,$dirs_error);
+               return array($dirs_searched, $files_searched, $dirs_error);
        }
 }