Skip to content

Commit 7ee890e

Browse files
committed
Replace substr()-based comparisons by substr_compare()
1 parent f1e1fef commit 7ee890e

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

plugins/PluginApi0Plugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ public function onPagesLoaded(
231231
$pages = [];
232232
foreach ($plainPages as &$pageData) {
233233
if (!isset($pageData['id'])) {
234-
if (substr($pageData['url'], 0, $baseUrlLength) === $baseUrl) {
235-
if ($urlRewritingEnabled && (substr($pageData['url'], $baseUrlLength, 1) === '?')) {
234+
if (substr_compare($pageData['url'], $baseUrl, 0, $baseUrlLength) === 0) {
235+
if ($urlRewritingEnabled && (substr_compare($pageData['url'], '?', $baseUrlLength, 1) === 0)) {
236236
$pageData['id'] = substr($pageData['url'], $baseUrlLength + 1);
237237
} else {
238238
$pageData['id'] = substr($pageData['url'], $baseUrlLength);

plugins/ThemeApi2Plugin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function twigEscapeStrategy($templateName)
138138

139139
if ($templatePath) {
140140
$themePath = realpath($this->getPico()->getThemesDir() . $this->getPico()->getTheme()) . '/';
141-
if (substr($templatePath, 0, strlen($themePath)) === $themePath) {
141+
if (substr_compare($templatePath, $themePath, 0, strlen($themePath)) === 0) {
142142
$themeApiVersion = $this->getPico()->getThemeApiVersion();
143143
return ($themeApiVersion >= PicoDeprecated::API_VERSION_3) ? $escapeStrategy : false;
144144
}
@@ -167,7 +167,7 @@ protected function getPluginFromPath($path)
167167
{
168168
$plugins = $this->getPico()->getPlugins();
169169
foreach ($this->pluginPaths as $pluginName => $pluginPath) {
170-
if ($pluginPath && (substr($path, 0, strlen($pluginPath)) === $pluginPath)) {
170+
if ($pluginPath && (substr_compare($path, $pluginPath, 0, strlen($pluginPath)) === 0)) {
171171
return $plugins[$pluginName];
172172
}
173173
}
@@ -190,7 +190,7 @@ protected function getPluginFromPath($path)
190190

191191
$this->pluginPaths[$pluginName] = $pluginPath;
192192

193-
if ($pluginPath && (substr($path, 0, strlen($pluginPath)) === $pluginPath)) {
193+
if ($pluginPath && (substr_compare($path, $pluginPath, 0, strlen($pluginPath)) === 0)) {
194194
return $plugins[$pluginName];
195195
}
196196
}

0 commit comments

Comments
 (0)