[TASK] Add/drop usage of preg_quote() where needed 38/19938/2
authorJigal van Hemert <jigal@xs4all.nl>
Sat, 13 Apr 2013 16:24:45 +0000 (18:24 +0200)
committerJigal van Hemert <jigal@xs4all.nl>
Sat, 13 Apr 2013 19:46:52 +0000 (21:46 +0200)
In some places preg_quote() is not used or is used incorrectly.
In other places there are preg_quote() calls which had no
real function.

Change-Id: If201394036d17a68cea41903f849c6c5ea11b069
Releases: 4.5, 4.6, 4.7, 6.0, 6.1
Resolves: #36793
Reviewed-on: https://review.typo3.org/19938
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
t3lib/class.t3lib_extmgm.php
t3lib/class.t3lib_iconworks.php
t3lib/class.t3lib_modsettings.php
t3lib/class.t3lib_parsehtml.php
t3lib/class.t3lib_parsehtml_proc.php
t3lib/db/class.t3lib_db_preparedstatement.php
t3lib/mail/class.t3lib_mail_swiftmaileradapter.php
t3lib/tree/pagetree/class.t3lib_tree_pagetree_dataprovider.php

index ff07290..1ed9d03 100644 (file)
@@ -312,8 +312,8 @@ final class t3lib_extMgm {
                                                $positionArray = t3lib_div::trimExplode(':', $position);
                                                if ($positionArray[0] == 'replace') {
                                                        foreach ($GLOBALS['TCA'][$table]['palettes'] as $palette => $paletteDetails) {
-                                                               if (preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0
-                                                                               && preg_match('/\b' . $positionArray[1] . '\b/', $paletteDetails['showitem']) > 0) {
+                                                               if (preg_match('/\b' . preg_quote($palette, '/') . '\b/', $typeDetails['showitem']) > 0
+                                                                               && preg_match('/\b' . preg_quote($positionArray[1], '/') . '\b/', $paletteDetails['showitem']) > 0) {
                                                                        self::addFieldsToPalette($table, $palette, $str, $position);
                                                                                // save that palette in case other types use it
                                                                        $palettesChanged[] = $palette;
@@ -327,8 +327,8 @@ final class t3lib_extMgm {
                                                                $fieldExists = TRUE;
                                                        } else {
                                                                foreach ($GLOBALS['TCA'][$table]['palettes'] as $palette => $paletteDetails) {
-                                                                       if (preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0
-                                                                       && preg_match('/\b' . $positionArray[1] . '\b/', $paletteDetails['showitem']) > 0) {
+                                                                       if (preg_match('/\b' . preg_quote($palette, '/') . '\b/', $typeDetails['showitem']) > 0
+                                                                       && preg_match('/\b' . preg_quote($positionArray[1], '/') . '\b/', $paletteDetails['showitem']) > 0) {
                                                                                $position = $positionArray[0] . ':--palette--;;' . $palette;
                                                                        }
                                                                }
@@ -339,7 +339,7 @@ final class t3lib_extMgm {
                                                        $fieldExists = TRUE;
                                                } else if(is_array($GLOBALS['TCA'][$table]['palettes'])) {
                                                        foreach ($GLOBALS['TCA'][$table]['palettes'] as $palette => $paletteDetails) {
-                                                               if (preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0
+                                                               if (preg_match('/\b' . preg_quote($palette, '/') . '\b/', $typeDetails['showitem']) > 0
                                                                && strpos($paletteDetails['showitem'], $str) !== FALSE) {
                                                                        $fieldExists = TRUE;
                                                                }
index f556ef9..703bb12 100644 (file)
@@ -397,7 +397,7 @@ final class t3lib_iconWorks {
                if (preg_match('/(.*)_i(\....)$/', $srcBasename, $matches)) {
                        $temp_path = dirname(PATH_thisScript) . '/';
                        if (!@is_file($temp_path . $backPath . $src)) {
-                               $srcOrg = preg_replace('/_i' . preg_quote($matches[2]) . '$/', $matches[2], $src);
+                               $srcOrg = preg_replace('/_i' . preg_quote($matches[2], '/') . '$/', $matches[2], $src);
                                $src = self::makeIcon($backPath . $srcOrg, 'disabled', 0, FALSE, $temp_path . $backPath . $srcOrg, $srcBasename);
                        }
                }
index 54bcb55..046e124 100644 (file)
@@ -245,7 +245,7 @@ class t3lib_modSettings {
                global $SOBE;
 
                $prefix = $prefix ? $prefix : $this->prefix;
-
+               $prefix = preg_quote($prefix, '/');
                foreach ($SOBE->MOD_SETTINGS as $key => $value) {
                        if (preg_match('/^' . $prefix . '/', $key)) {
                                $this->storeList[$key] = $key;
index b7d822e..b4ba28a 100644 (file)
@@ -304,7 +304,7 @@ class t3lib_parsehtml {
                                        $wrapArr = array('###', '###');
                                }
 
-                               $content = preg_replace('/' . preg_quote($wrapArr[0]) . '([A-Z0-9_|\-]*)' . preg_quote($wrapArr[1]) . '/is', '', $content);
+                               $content = preg_replace('/' . preg_quote($wrapArr[0], '/') . '([A-Z0-9_|\-]*)' . preg_quote($wrapArr[1]) . '/is', '', $content);
                        }
                }
 
@@ -331,6 +331,9 @@ class t3lib_parsehtml {
         */
        function splitIntoBlock($tag, $content, $eliminateExtraEndTags = 0) {
                $tags = array_unique(t3lib_div::trimExplode(',', $tag, 1));
+               foreach ($tags as &$tag) {
+                       $tag = preg_quote($tag, '/');
+               }
                $regexStr = '/\<\/?(' . implode('|', $tags) . ')(\s*\>|\s[^\>]*\>)/si';
 
                $parts = preg_split($regexStr, $content);
@@ -432,6 +435,9 @@ class t3lib_parsehtml {
         */
        function splitTags($tag, $content) {
                $tags = t3lib_div::trimExplode(',', $tag, 1);
+               foreach ($tags as &$tag) {
+                       $tag = preg_quote($tag, '/');
+               }
                $regexStr = '/\<(' . implode('|', $tags) . ')(\s[^>]*)?\/?>/si';
                $parts = preg_split($regexStr, $content);
 
@@ -624,8 +630,8 @@ class t3lib_parsehtml {
                        // Block tags, must have endings...
                $blockTags = explode(',', $blockTags);
                foreach ($blockTags as $tagName) {
-                       $countBegin = count(preg_split('/\<' . $tagName . '(\s|\>)/s', $content)) - 1;
-                       $countEnd = count(preg_split('/\<\/' . $tagName . '(\s|\>)/s', $content)) - 1;
+                       $countBegin = count(preg_split('/\<' . preg_quote($tagName, '/') . '(\s|\>)/s', $content)) - 1;
+                       $countEnd = count(preg_split('/\<\/' . preg_quote($tagName, '/') . '(\s|\>)/s', $content)) - 1;
                        $analyzedOutput['blocks'][$tagName] = array($countBegin, $countEnd, $countBegin - $countEnd);
                        if ($countBegin) {
                                $analyzedOutput['counts'][$tagName] = $countBegin;
@@ -642,8 +648,8 @@ class t3lib_parsehtml {
                        // Solo tags, must NOT have endings...
                $soloTags = explode(',', $soloTags);
                foreach ($soloTags as $tagName) {
-                       $countBegin = count(preg_split('/\<' . $tagName . '(\s|\>)/s', $content)) - 1;
-                       $countEnd = count(preg_split('/\<\/' . $tagName . '(\s|\>)/s', $content)) - 1;
+                       $countBegin = count(preg_split('/\<' . preg_quote($tagName, '/') . '(\s|\>)/s', $content)) - 1;
+                       $countEnd = count(preg_split('/\<\/' . preg_quote($tagName, '/') . '(\s|\>)/s', $content)) - 1;
                        $analyzedOutput['solo'][$tagName] = array($countBegin, $countEnd);
                        if ($countBegin) {
                                $analyzedOutput['counts'][$tagName] = $countBegin;
@@ -1151,7 +1157,7 @@ class t3lib_parsehtml {
        function mapTags($value, $tags = array(), $ltChar = '<', $ltChar2 = '<') {
 
                foreach ($tags as $from => $to) {
-                       $value = preg_replace('/' . preg_quote($ltChar) . '(\/)?' . $from . '\s([^\>])*(\/)?\>/', $ltChar2 . '$1' . $to . ' $2$3>', $value);
+                       $value = preg_replace('/' . preg_quote($ltChar, '/') . '(\/)?' . $from . '\s([^\>])*(\/)?\>/', $ltChar2 . '$1' . $to . ' $2$3>', $value);
                }
                return $value;
        }
index c673ba6..c899a21 100644 (file)
@@ -844,7 +844,7 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                                        if (!isset($this->procOptions['typolist']) || $this->procOptions['typolist']) {
                                                                $parts = $this->getAllParts($this->splitIntoBlock('LI', $this->removeFirstAndLastTag($blockSplit[$k])), 1, 0);
                                                                foreach ($parts as $k2 => $value) {
-                                                                       $parts[$k2] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', '', $parts[$k2]); // remove all linesbreaks!
+                                                                       $parts[$k2] = preg_replace('/[' . LF . CR . ']+/', '', $parts[$k2]); // remove all linesbreaks!
                                                                        $parts[$k2] = $this->defaultTStagMapping($parts[$k2], 'db');
                                                                        $parts[$k2] = $this->cleanFontTags($parts[$k2], 0, 0, 0);
                                                                        $parts[$k2] = $this->HTMLcleaner_db($parts[$k2], strtolower($this->procOptions['allowTagsInTypolists'] ? $this->procOptions['allowTagsInTypolists'] : 'br,font,b,i,u,a,img,span,strong,em'));
@@ -857,14 +857,14 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                                                $blockSplit[$k] = '<typolist' . $params . '>' . LF . implode(LF, $parts) . LF . '</typolist>' . $lastBR;
                                                        }
                                                } else {
-                                                       $blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
+                                                       $blockSplit[$k] = preg_replace('/[' . LF . CR . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
                                                }
                                        break;
                                        case 'table': // Tables are NOT allowed in any form (unless preserveTables is set or CSS is the mode)
                                                if (!$this->procOptions['preserveTables'] && !$css) {
                                                        $blockSplit[$k] = $this->TS_transform_db($this->removeTables($blockSplit[$k]));
                                                } else {
-                                                       $blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
+                                                       $blockSplit[$k] = preg_replace('/[' . LF . CR . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
                                                }
                                        break;
                                        case 'h1':
@@ -899,23 +899,23 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                                        }
                                                } else {
                                                                // Eliminate true linebreaks inside Hx tags
-                                                       $blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
+                                                       $blockSplit[$k] = preg_replace('/[' . LF . CR . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
                                                }
                                        break;
                                        default:
                                                        // Eliminate true linebreaks inside other headlist tags
-                                               $blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
+                                               $blockSplit[$k] = preg_replace('/[' . LF . CR . ']+/', ' ', $this->transformStyledATags($blockSplit[$k])) . $lastBR;
                                        break;
                                }
                        } else { // NON-block:
                                if (strcmp(trim($blockSplit[$k]), '')) {
                                        $blockSplit[$k] = preg_replace('/<hr\/>/', '<hr />', $blockSplit[$k]);
                                                // Remove linebreaks preceding hr tags
-                                       $blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+<(hr)(\s[^>\/]*)?[[:space:]]*\/?>/', '<$1$2/>', $blockSplit[$k]);
+                                       $blockSplit[$k] = preg_replace('/[' . LF . CR . ']+<(hr)(\s[^>\/]*)?[[:space:]]*\/?>/', '<$1$2/>', $blockSplit[$k]);
                                                // Remove linebreaks following hr tags
-                                       $blockSplit[$k] = preg_replace('/<(hr)(\s[^>\/]*)?[[:space:]]*\/?>[' . preg_quote(LF . CR) . ']+/', '<$1$2/>', $blockSplit[$k]);
+                                       $blockSplit[$k] = preg_replace('/<(hr)(\s[^>\/]*)?[[:space:]]*\/?>[' . LF . CR . ']+/', '<$1$2/>', $blockSplit[$k]);
                                                // Replace other linebreaks with space
-                                       $blockSplit[$k] = preg_replace('/[' . preg_quote(LF . CR) . ']+/', ' ', $blockSplit[$k]);
+                                       $blockSplit[$k] = preg_replace('/[' . LF . CR . ']+/', ' ', $blockSplit[$k]);
                                        $blockSplit[$k] = $this->divideIntoLines($blockSplit[$k]) . $lastBR;
                                        $blockSplit[$k] = $this->transformStyledATags($blockSplit[$k]);
                                } else {
@@ -1255,8 +1255,8 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                if (count($divSplit) <= 1 || $count <= 0) {
                                // Wrap hr tags with LF's
                        $newValue = preg_replace('/<(hr)(\s[^>\/]*)?[[:space:]]*\/?>/i', LF . '<$1$2/>' . LF, $value);
-                       $newValue = preg_replace('/' . preg_quote(LF . LF) . '/i', LF, $newValue);
-                       $newValue = preg_replace('/(^' . preg_quote(LF) . ')|(' . preg_quote(LF) . '$)/i', '', $newValue);
+                       $newValue = preg_replace('/' . LF . LF . '/i', LF, $newValue);
+                       $newValue = preg_replace('/(^' . LF . ')|(' . LF . '$)/i', '', $newValue);
                        return $newValue;
                }
 
@@ -1348,8 +1348,8 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                $divSplit[$k] = trim(strip_tags($divSplit[$k], '<' . implode('><', $allowTagsOutside) . '>'));
                                        // Wrap hr tags with LF's
                                $divSplit[$k] = preg_replace('/<(hr)(\s[^>\/]*)?[[:space:]]*\/?>/i', LF . '<$1$2/>' . LF, $divSplit[$k]);
-                               $divSplit[$k] = preg_replace('/' . preg_quote(LF . LF) . '/i', LF, $divSplit[$k]);
-                               $divSplit[$k] = preg_replace('/(^' . preg_quote(LF) . ')|(' . preg_quote(LF) . '$)/i', '', $divSplit[$k]);
+                               $divSplit[$k] = preg_replace('/' . LF . LF . '/i', LF, $divSplit[$k]);
+                               $divSplit[$k] = preg_replace('/(^' . LF . ')|(' . LF . '$)/i', '', $divSplit[$k]);
                                if (!strcmp($divSplit[$k], '')) {
                                        unset($divSplit[$k]);
                                } // Remove part if it's empty
index 40677f3..d61f174 100644 (file)
@@ -500,7 +500,7 @@ class t3lib_db_PreparedStatement {
                                }
                                // Replace the marker (not preceeded by a word character or a ':' but
                                // followed by a word boundary)
-                               $query = preg_replace('/(?<![\w:])' . $key . '\b/', $this->parameterWrapToken . $key . $this->parameterWrapToken, $query);
+                               $query = preg_replace('/(?<![\w:])' . preg_quote($key, '/') . '\b/', $this->parameterWrapToken . $key . $this->parameterWrapToken, $query);
                        } else {
                                $unnamedParameterCount++;
                        }
index cd11f0c..44820f7 100644 (file)
@@ -224,7 +224,7 @@ class t3lib_mail_SwiftMailerAdapter implements t3lib_mail_MailerAdapter {
        protected function setBody($body) {
                if ($this->boundary) {
                                // handle multi-part
-                       $bodyParts = preg_split('/--' . preg_quote($this->boundary) . '(--)?/m', $body, NULL, PREG_SPLIT_NO_EMPTY);
+                       $bodyParts = preg_split('/--' . preg_quote($this->boundary, '/') . '(--)?/m', $body, NULL, PREG_SPLIT_NO_EMPTY);
                        foreach ($bodyParts as $bodyPart) {
                                        // skip empty parts
                                if (trim($bodyPart) == '') {
index 97fb639..dedccc0 100644 (file)
@@ -155,6 +155,7 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
                }
 
                $isNumericSearchFilter = (is_numeric($searchFilter) && $searchFilter > 0);
+               $searchFilterQuoted = preg_quote($searchFilter, '/');
                $nodeId = intval($node->getId());
                foreach ($records as $record) {
                        $record = t3lib_tree_pagetree_Commands::getNodeRecord($record['uid']);
@@ -200,7 +201,7 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
                                        if ($isNumericSearchFilter && intval($rootlineElement['uid']) === intval($searchFilter)) {
                                                $text = str_replace('$1', $refNode->getText(), $replacement);
                                        } else {
-                                               $text = preg_replace('/(' . $searchFilter . ')/i', $replacement, $refNode->getText());
+                                               $text = preg_replace('/(' . $searchFilterQuoted . ')/i', $replacement, $refNode->getText());
                                        }
 
                                        $refNode->setText(
@@ -394,4 +395,4 @@ if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLA
        include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/tree/pagetree/class.t3lib_tree_pagetree_dataprovider.php']);
 }
 
-?>
\ No newline at end of file
+?>