Commit cde9c8c5 authored by Andreas Fernandez's avatar Andreas Fernandez Committed by Frank Nägler
Browse files

[BUGFIX] Use `strpos()` over `strstr()`

This patch replaces all usages of `strstr()` and its friends where the
existence of a certain substring is checked, but the result isn't used at
all with `strpos()`, which uses less memory.

Resolves: #88922
Releases: master
Change-Id: Ie45589ac9410e22e1b48e82dd8086eadb6d74107
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61445

Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Frank Nägler's avatarFrank Naegler <frank.naegler@typo3.org>
Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Frank Nägler's avatarFrank Naegler <frank.naegler@typo3.org>
parent 895d737f
......@@ -732,7 +732,7 @@ class NewRecordController
$allowedTableList = $GLOBALS['PAGES_TYPES']['default']['allowedTables'];
}
// If all tables or the table is listed as an allowed type, return TRUE
if (strstr($allowedTableList, '*') || GeneralUtility::inList($allowedTableList, $table)) {
if (strpos($allowedTableList, '*') !== false || GeneralUtility::inList($allowedTableList, $table)) {
return true;
}
......
......@@ -1080,7 +1080,7 @@ abstract class AbstractItemProvider
) {
$foreignTableClause = $result['processedTca']['columns'][$localFieldName]['config']['foreign_table_where'];
// Replace possible markers in query
if (strstr($foreignTableClause, '###REC_FIELD_')) {
if (strpos($foreignTableClause, '###REC_FIELD_') !== false) {
// " AND table.field='###REC_FIELD_field1###' AND ..." -> array(" AND table.field='", "field1###' AND ...")
$whereClauseParts = explode('###REC_FIELD_', $foreignTableClause);
foreach ($whereClauseParts as $key => $value) {
......
......@@ -2009,7 +2009,7 @@ class BackendUtility
}
}
// If this field is a password field, then hide the password by changing it to a random number of asterisk (*)
if (!empty($theColConf['eval']) && stristr($theColConf['eval'], 'password')) {
if (!empty($theColConf['eval']) && stripos($theColConf['eval'], 'password') !== false) {
$l = '';
$randomNumber = rand(5, 12);
for ($i = 0; $i < $randomNumber; $i++) {
......
......@@ -440,7 +440,7 @@ class BackendUserAuthentication extends AbstractUserAuthentication
}
// If $conf['access'] is set but not with 'admin' then we return TRUE, if the module is found in the modList
$acs = false;
if (!strstr($conf['access'], 'admin') && $conf['name']) {
if (strpos($conf['access'], 'admin') === false && $conf['name']) {
$acs = $this->check('modules', $conf['name']);
}
if (!$acs) {
......
......@@ -285,7 +285,7 @@ class SystemEnvironmentBuilder
protected static function getTypo3Os()
{
$typoOs = '';
if (!stristr(PHP_OS, 'darwin') && !stristr(PHP_OS, 'cygwin') && stristr(PHP_OS, 'win')) {
if (stripos(PHP_OS, 'darwin') === false && stripos(PHP_OS, 'cygwin') === false && stripos(PHP_OS, 'win') !== false) {
$typoOs = 'WIN';
}
return $typoOs;
......
......@@ -825,7 +825,7 @@ class QueryGenerator
}
}
}
if (stristr($fieldSetup['allowed'], ',')) {
if (strpos($fieldSetup['allowed'], ',') !== false) {
$from_table_Arr = explode(',', $fieldSetup['allowed']);
$useTablePrefix = 1;
if (!$fieldSetup['prepend_tname']) {
......@@ -835,16 +835,16 @@ class QueryGenerator
->from($table)
->execute();
while ($row = $statement->fetch()) {
if (stristr($row[$fieldName], ',')) {
if (strpos($row[$fieldName], ',') !== false) {
$checkContent = explode(',', $row[$fieldName]);
foreach ($checkContent as $singleValue) {
if (!stristr($singleValue, '_')) {
if (strpos($singleValue, '_') === false) {
$dontPrefixFirstTable = 1;
}
}
} else {
$singleValue = $row[$fieldName];
if ($singleValue !== '' && !stristr($singleValue, '_')) {
if ($singleValue !== '' && strpos($singleValue, '_') === false) {
$dontPrefixFirstTable = 1;
}
}
......
......@@ -981,7 +981,7 @@ class QueryView
}
}
}
if (stristr($fieldSetup['allowed'], ',')) {
if (strpos($fieldSetup['allowed'], ',') !== false) {
$from_table_Arr = explode(',', $fieldSetup['allowed']);
$useTablePrefix = 1;
if (!$fieldSetup['prepend_tname']) {
......@@ -989,16 +989,16 @@ class QueryView
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$statement = $queryBuilder->select($fieldName)->from($table)->execute();
while ($row = $statement->fetch()) {
if (stristr($row[$fieldName], ',')) {
if (strpos($row[$fieldName], ',') !== false) {
$checkContent = explode(',', $row[$fieldName]);
foreach ($checkContent as $singleValue) {
if (!stristr($singleValue, '_')) {
if (strpos($singleValue, '_') === false) {
$dontPrefixFirstTable = 1;
}
}
} else {
$singleValue = $row[$fieldName];
if ($singleValue !== '' && !stristr($singleValue, '_')) {
if ($singleValue !== '' && strpos($singleValue, '_') === false) {
$dontPrefixFirstTable = 1;
}
}
......
......@@ -969,7 +969,7 @@ class ReferenceIndex implements LoggerAwareInterface
}
}
// Set in data array:
if (!strstr($softref['tokenizedContent'], '{softref:')) {
if (strpos($softref['tokenizedContent'], '{softref:') === false) {
if ($flexPointer) {
$flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
$dataArray[$refRec['tablename']][$refRec['recuid']][$refRec['field']]['data'] = [];
......
......@@ -384,7 +384,7 @@ class SoftReferenceIndex implements SingletonInterface
$pU = @parse_url($link_param);
// If it's a mail address:
if (strstr($link_param, '@') && !$pU['scheme']) {
if (strpos($link_param, '@') !== false && !$pU['scheme']) {
$link_param = preg_replace('/^mailto:/i', '', $link_param);
$finalTagParts['LINK_TYPE'] = 'mailto';
$finalTagParts['url'] = trim($link_param);
......
......@@ -1947,12 +1947,12 @@ class GraphicalFunctions
$cParts = explode(':', $string, 2);
// Finding the RGB definitions of the color:
$string = $cParts[0];
if (strstr($string, '#')) {
if (strpos($string, '#') !== false) {
$string = preg_replace('/[^A-Fa-f0-9]*/', '', $string);
$col[] = hexdec(substr($string, 0, 2));
$col[] = hexdec(substr($string, 2, 2));
$col[] = hexdec(substr($string, 4, 2));
} elseif (strstr($string, ',')) {
} elseif (strpos($string, ',') !== false) {
$string = preg_replace('/[^,0-9]*/', '', $string);
$strArr = explode(',', $string);
$col[] = (int)$strArr[0];
......@@ -2283,12 +2283,8 @@ class GraphicalFunctions
*/
public function getImageScale($info, $w, $h, $options)
{
if (strstr($w . $h, 'm')) {
$max = 1;
} else {
$max = 0;
}
if (strstr($w . $h, 'c')) {
$max = strpos($w . $h, 'm') !== false ? 1 : 0;
if (strpos($w . $h, 'c') !== false) {
$out['cropH'] = (int)substr(strstr($w, 'c'), 1);
$out['cropV'] = (int)substr(strstr($h, 'c'), 1);
$crs = true;
......
......@@ -115,7 +115,7 @@ class LinkService implements SingletonInterface
if ($fragment) {
$result['fragment'] = $fragment;
}
} elseif (stripos($urn, '://') && $this->handlers[self::TYPE_URL]) {
} elseif (strpos($urn, '://') && $this->handlers[self::TYPE_URL]) {
$result = $this->handlers[self::TYPE_URL]->resolveHandlerData(['url' => $urn]);
$result['type'] = self::TYPE_URL;
} elseif (stripos($urn, 'mailto:') === 0 && $this->handlers[self::TYPE_EMAIL]) {
......
......@@ -577,15 +577,15 @@ class ExtendedTemplateService extends TemplateService
}
} else {
// The value has matched
if (stristr($arr[$key], $searchString)) {
if (stripos($arr[$key], $searchString) !== false) {
$this->tsbrowser_searchKeys[$depth] += 2;
}
// The key has matches
if (stristr($key, $searchString)) {
if (stripos($key, $searchString) !== false) {
$this->tsbrowser_searchKeys[$depth] += 4;
}
// Just open this subtree if the parent key has matched the search
if (stristr($depth_in, $searchString)) {
if (stripos($depth_in, $searchString) !== false) {
$this->tsbrowser_searchKeys[$depth] = 1;
}
}
......@@ -920,7 +920,7 @@ class ExtendedTemplateService extends TemplateService
}
$parts = explode(';', $line);
foreach ($parts as $par) {
if (strstr($par, '=')) {
if (strpos($par, '=') !== false) {
$keyValPair = explode('=', $par, 2);
switch (trim(strtolower($keyValPair[0]))) {
case 'type':
......
......@@ -111,7 +111,7 @@ class TypoScriptService
}
} elseif (is_string($val)) {
// Splitting of all values on this level of the TypoScript object tree:
if ($cKey === 'noTrimWrap' || (!strstr($val, '|*|') && !strstr($val, '||'))) {
if ($cKey === 'noTrimWrap' || (strpos($val, '|*|') === false && strpos($val, '||') === false)) {
for ($aKey = 0; $aKey < $splitCount; $aKey++) {
$finalConfiguration[$aKey][$cKey] = $val;
}
......
......@@ -79,7 +79,7 @@ class VersionNumberUtility
trigger_error('Method ' . __METHOD__ . ' will be removed in TYPO3 11.0', E_USER_DEPRECATED);
$versionRange = [];
if (strstr($version, '-')) {
if (strpos($version, '-') !== false) {
$versionRange = explode('-', $version, 2);
} else {
$versionRange[0] = $version;
......
......@@ -1215,7 +1215,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
);
}
if ($dimension) {
if (strstr($dimension, 'c') !== false && ($dimensionKey === 'width' || $dimensionKey === 'height')) {
if (strpos($dimension, 'c') !== false && ($dimensionKey === 'width' || $dimensionKey === 'height')) {
$dimensionParts = explode('c', $dimension, 2);
$dimension = ((int)$dimensionParts[0] * $pixelDensity) . 'c';
if ($dimensionParts[1]) {
......@@ -3850,7 +3850,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
$newstring .= $pieces[0];
$match_len = strlen($data) - (strlen($pieces[0]) + strlen($pieces[1]));
$inTag = false;
if (strstr($pieces[0], '<') || strstr($pieces[0], '>')) {
if (strpos($pieces[0], '<') !== false || strpos($pieces[0], '>') !== false) {
// Returns TRUE, if a '<' is closer to the string-end than '>'.
// This is the case if we're INSIDE a tag (that could have been
// made by makelinks...) and we must secure, that the inside of a tag is
......@@ -4130,14 +4130,14 @@ class ContentObjectRenderer implements LoggerAwareInterface
$keep = $conf['keep'];
$linkParts = parse_url($scheme . $parts[0]);
$linktxt = '';
if (strstr($keep, 'scheme')) {
if (strpos($keep, 'scheme') !== false) {
$linktxt = $scheme;
}
$linktxt .= $linkParts['host'];
if (strstr($keep, 'path')) {
if (strpos($keep, 'path') !== false) {
$linktxt .= $linkParts['path'];
// Added $linkParts['query'] 3/12
if (strstr($keep, 'query') && $linkParts['query']) {
if (strpos($keep, 'query') !== false && $linkParts['query']) {
$linktxt .= '?' . $linkParts['query'];
} elseif ($linkParts['path'] === '/') {
$linktxt = substr($linktxt, 0, -1);
......@@ -4475,7 +4475,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
*/
public function getFieldVal($field)
{
if (!strstr($field, '//')) {
if (strpos($field, '//') === false) {
return $this->data[trim($field)] ?? null;
}
$sections = GeneralUtility::trimExplode('//', $field, true);
......
......@@ -76,7 +76,7 @@ class TemplateContentObject extends AbstractContentObject
// Getting marks
if (is_array($conf['marks.'])) {
foreach ($conf['marks.'] as $theKey => $theValue) {
if (!strstr($theKey, '.')) {
if (strpos($theKey, '.') === false) {
$content = str_replace($PRE . $theKey . $POST, $this->cObj->cObjGetSingle($theValue, $conf['marks.'][$theKey . '.'], 'marks.' . $theKey), $content);
}
}
......@@ -84,7 +84,7 @@ class TemplateContentObject extends AbstractContentObject
// Getting subparts.
if (is_array($conf['subparts.'])) {
foreach ($conf['subparts.'] as $theKey => $theValue) {
if (!strstr($theKey, '.')) {
if (strpos($theKey, '.') === false) {
$subpart = $this->templateService->getSubpart($content, $PRE . $theKey . $POST);
if ($subpart) {
$this->cObj->setCurrentVal($subpart);
......@@ -96,7 +96,7 @@ class TemplateContentObject extends AbstractContentObject
// Getting subpart wraps
if (is_array($conf['wraps.'])) {
foreach ($conf['wraps.'] as $theKey => $theValue) {
if (!strstr($theKey, '.')) {
if (strpos($theKey, '.') === false) {
$subpart = $this->templateService->getSubpart($content, $PRE . $theKey . $POST);
if ($subpart) {
$this->cObj->setCurrentVal($subpart);
......@@ -110,7 +110,7 @@ class TemplateContentObject extends AbstractContentObject
// Getting subparts.
if (is_array($conf['subparts.'])) {
foreach ($conf['subparts.'] as $theKey => $theValue) {
if (!strstr($theKey, '.')) {
if (strpos($theKey, '.') === false) {
$subpart = $this->templateService->getSubpart($content, $PRE . $theKey . $POST);
if ($subpart) {
$GLOBALS['TSFE']->register['SUBPART_' . $theKey] = $subpart;
......@@ -123,7 +123,7 @@ class TemplateContentObject extends AbstractContentObject
// Getting marks
if (is_array($conf['marks.'])) {
foreach ($conf['marks.'] as $theKey => $theValue) {
if (!strstr($theKey, '.')) {
if (strpos($theKey, '.') === false) {
$marks[$theKey]['name'] = $theValue;
$marks[$theKey]['conf'] = $conf['marks.'][$theKey . '.'];
}
......@@ -132,7 +132,7 @@ class TemplateContentObject extends AbstractContentObject
// Getting subpart wraps
if (is_array($conf['wraps.'])) {
foreach ($conf['wraps.'] as $theKey => $theValue) {
if (!strstr($theKey, '.')) {
if (strpos($theKey, '.') === false) {
$wraps[$theKey]['name'] = $theValue;
$wraps[$theKey]['conf'] = $conf['wraps.'][$theKey . '.'];
}
......
......@@ -172,11 +172,7 @@ EOF;
*/
protected function processImage()
{
if (strstr($this->width . $this->height, 'm')) {
$max = 'm';
} else {
$max = '';
}
$max = strpos($this->width . $this->height, 'm') !== false ? 'm' : '';
$this->height = MathUtility::forceIntegerInRange($this->height, 0);
$this->width = MathUtility::forceIntegerInRange($this->width, 0) . $max;
......
......@@ -2403,7 +2403,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
if (@preg_match($needle, $haystack)) {
$isAllowed = true;
}
} elseif (strstr($needle, '-')) {
} elseif (strpos($needle, '-') !== false) {
// Range
if (MathUtility::canBeInterpretedAsInteger($haystack)) {
$range = explode('-', $needle);
......@@ -2411,11 +2411,11 @@ class TypoScriptFrontendController implements LoggerAwareInterface
$isAllowed = true;
}
}
} elseif (strstr($needle, '|')) {
} elseif (strpos($needle, '|') !== false) {
// List
// Trim the input
$haystack = str_replace(' ', '', $haystack);
if (strstr('|' . $needle . '|', '|' . $haystack . '|')) {
if (strpos('|' . $needle . '|', '|' . $haystack . '|') !== false) {
$isAllowed = true;
}
} elseif ((string)$needle === (string)$haystack) {
......
......@@ -1678,7 +1678,7 @@ class Import extends ImportExport
return null;
}
$initStrDat = explode(':', $initStr);
if (strstr($initStrDat[0], 'Warning')) {
if (strpos($initStrDat[0], 'Warning') !== false) {
$this->error('File read error: Warning message in file. (' . $initStr . fgets($fd) . ')');
return null;
}
......
......@@ -826,7 +826,7 @@ abstract class ImportExport
$allowedTableList = $GLOBALS['PAGES_TYPES'][$doktype]['allowedTables'] ?? $GLOBALS['PAGES_TYPES']['default']['allowedTables'];
$allowedArray = GeneralUtility::trimExplode(',', $allowedTableList, true);
// If all tables or the table is listed as an allowed type, return TRUE
if (strstr($allowedTableList, '*') || in_array($checkTable, $allowedArray)) {
if (strpos($allowedTableList, '*') !== false || in_array($checkTable, $allowedArray)) {
return true;
}
return false;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment