Replaced strpos() with simplified realization (#1172)

This commit is contained in:
Roman Kelesidis 2023-11-27 20:12:13 +03:00 committed by GitHub
commit 493cd910cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 24 additions and 24 deletions

View file

@ -255,7 +255,7 @@ if (!isset($_REQUEST['dosearch'])) {
$username = str_replace("\*", '%', trim(strip_tags(strtolower($username)))); $username = str_replace("\*", '%', trim(strip_tags(strtolower($username))));
if (false !== strpos($username, '%')) { if (str_contains($username, '%')) {
$op = 'LIKE'; $op = 'LIKE';
} else { } else {
$op = '='; $op = '=';
@ -276,7 +276,7 @@ if (!isset($_REQUEST['dosearch'])) {
$email = str_replace("\*", '%', trim(strip_tags(strtolower($email)))); $email = str_replace("\*", '%', trim(strip_tags(strtolower($email))));
if (false !== strpos($email, '%')) { if (str_contains($email, '%')) {
$op = 'LIKE'; $op = 'LIKE';
} else { } else {
$op = '='; $op = '=';
@ -524,7 +524,7 @@ if (!isset($_REQUEST['dosearch'])) {
break; break;
case 'equals': case 'equals':
// looking for a - // looking for a -
if (false !== strpos($postcount_value, '-')) { if (str_contains($postcount_value, '-')) {
$range = preg_split('/[-\s]+/', $postcount_value); $range = preg_split('/[-\s]+/', $postcount_value);
$range_begin = (int)$range[0]; $range_begin = (int)$range[0];
@ -571,7 +571,7 @@ if (!isset($_REQUEST['dosearch'])) {
$userfield_value = str_replace("\*", '%', trim(strip_tags(strtolower($userfield_value)))); $userfield_value = str_replace("\*", '%', trim(strip_tags(strtolower($userfield_value))));
if (false !== strpos($userfield_value, '%')) { if (str_contains($userfield_value, '%')) {
$op = 'LIKE'; $op = 'LIKE';
} else { } else {
$op = '='; $op = '=';

View file

@ -27,7 +27,7 @@ if (isset($_GET['?info_hash']) && !isset($_GET['info_hash'])) {
} }
// Initial request verification // Initial request verification
if (strpos($_SERVER['REQUEST_URI'], 'scrape') !== false) { if (str_contains($_SERVER['REQUEST_URI'], 'scrape')) {
msg_die('Please disable SCRAPE!'); msg_die('Please disable SCRAPE!');
} }

2
dl.php
View file

@ -38,7 +38,7 @@ function send_file_to_browser($attachment, $upload_dir)
// Correct the mime type - we force application/octet-stream for all files, except images // Correct the mime type - we force application/octet-stream for all files, except images
// Please do not change this, it is a security precaution // Please do not change this, it is a security precaution
if (false === strpos($attachment['mimetype'], 'image')) { if (!str_contains($attachment['mimetype'], 'image')) {
$attachment['mimetype'] = 'application/octet-stream'; $attachment['mimetype'] = 'application/octet-stream';
} }

View file

@ -41,7 +41,7 @@ switch ($mode) {
$dir = $template->cachedir; $dir = $template->cachedir;
$res = @opendir($dir); $res = @opendir($dir);
while (($file = readdir($res)) !== false) { while (($file = readdir($res)) !== false) {
if (0 === strpos($file, $match)) { if (str_starts_with($file, $match)) {
@unlink($dir . $file); @unlink($dir . $file);
} }
} }

View file

@ -382,7 +382,7 @@ function attachment_sync_topic($topics)
*/ */
function get_extension($filename) function get_extension($filename)
{ {
if (false === strpos($filename, '.')) { if (!str_contains($filename, '.')) {
return ''; return '';
} }
$extension = strrchr(strtolower($filename), '.'); $extension = strrchr(strtolower($filename), '.');

View file

@ -26,9 +26,9 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0,
$post_id_array = []; $post_id_array = [];
if (!is_array($attach_id_array)) { if (!is_array($attach_id_array)) {
if (false !== strpos($attach_id_array, ', ')) { if (str_contains($attach_id_array, ', ')) {
$attach_id_array = explode(', ', $attach_id_array); $attach_id_array = explode(', ', $attach_id_array);
} elseif (false !== strpos($attach_id_array, ',')) { } elseif (str_contains($attach_id_array, ',')) {
$attach_id_array = explode(',', $attach_id_array); $attach_id_array = explode(',', $attach_id_array);
} else { } else {
$attach_id = (int)$attach_id_array; $attach_id = (int)$attach_id_array;
@ -67,9 +67,9 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0,
return; return;
} }
if (false !== strpos($post_id_array, ', ')) { if (str_contains($post_id_array, ', ')) {
$post_id_array = explode(', ', $post_id_array); $post_id_array = explode(', ', $post_id_array);
} elseif (false !== strpos($post_id_array, ',')) { } elseif (str_contains($post_id_array, ',')) {
$post_id_array = explode(',', $post_id_array); $post_id_array = explode(',', $post_id_array);
} else { } else {
$post_id = (int)$post_id_array; $post_id = (int)$post_id_array;
@ -112,9 +112,9 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0,
} }
if (!is_array($attach_id_array)) { if (!is_array($attach_id_array)) {
if (false !== strpos($attach_id_array, ', ')) { if (str_contains($attach_id_array, ', ')) {
$attach_id_array = explode(', ', $attach_id_array); $attach_id_array = explode(', ', $attach_id_array);
} elseif (false !== strpos($attach_id_array, ',')) { } elseif (str_contains($attach_id_array, ',')) {
$attach_id_array = explode(',', $attach_id_array); $attach_id_array = explode(',', $attach_id_array);
} else { } else {
$attach_id = (int)$attach_id_array; $attach_id = (int)$attach_id_array;

View file

@ -97,7 +97,7 @@ define('CRON_RUNNING', TRIGGERS_DIR . '/cron_running');
// Gzip // Gzip
define('GZIP_OUTPUT_ALLOWED', extension_loaded('zlib') && !ini_get('zlib.output_compression')); define('GZIP_OUTPUT_ALLOWED', extension_loaded('zlib') && !ini_get('zlib.output_compression'));
define('UA_GZIP_SUPPORTED', isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false); define('UA_GZIP_SUPPORTED', isset($_SERVER['HTTP_ACCEPT_ENCODING']) && str_contains($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'));
// Torrents (reserved: -1) // Torrents (reserved: -1)
define('TOR_NOT_APPROVED', 0); // не проверено define('TOR_NOT_APPROVED', 0); // не проверено

View file

@ -553,7 +553,7 @@ function url_arg($url, $arg, $value, $amp = '&')
$url = str_replace($cur, $new, $url); $url = str_replace($cur, $new, $url);
} // добавляем параметр } // добавляем параметр
elseif (null !== $value) { elseif (null !== $value) {
$div = (strpos($url, '?') !== false) ? $amp : '?'; $div = str_contains($url, '?') ? $amp : '?';
$url = $url . $div . $arg . '=' . urlencode($value); $url = $url . $div . $arg . '=' . urlencode($value);
} }
return $url . $anchor; return $url . $anchor;
@ -1469,7 +1469,7 @@ function redirect($url)
trigger_error("Headers already sent in $filename($linenum)", E_USER_ERROR); trigger_error("Headers already sent in $filename($linenum)", E_USER_ERROR);
} }
if (false !== strpos(urldecode($url), "\n") || false !== strpos(urldecode($url), "\r") || false !== strpos(urldecode($url), ';url')) { if (str_contains(urldecode($url), "\n") || str_contains(urldecode($url), "\r") || str_contains(urldecode($url), ';url')) {
bb_die('Tried to redirect to potentially insecure url'); bb_die('Tried to redirect to potentially insecure url');
} }

View file

@ -32,7 +32,7 @@ $login_errors = [];
if (preg_match('/^redirect=([a-z0-9\.#\/\?&=\+\-_]+)/si', $_SERVER['QUERY_STRING'], $matches)) { if (preg_match('/^redirect=([a-z0-9\.#\/\?&=\+\-_]+)/si', $_SERVER['QUERY_STRING'], $matches)) {
$redirect_url = $matches[1]; $redirect_url = $matches[1];
if (false === strpos($redirect_url, '?') && $first_amp = strpos($redirect_url, '&')) { if (!str_contains($redirect_url, '?') && $first_amp = strpos($redirect_url, '&')) {
$redirect_url[$first_amp] = '?'; $redirect_url[$first_amp] = '?';
} }
} elseif (!empty($_POST['redirect'])) { } elseif (!empty($_POST['redirect'])) {
@ -43,7 +43,7 @@ if (preg_match('/^redirect=([a-z0-9\.#\/\?&=\+\-_]+)/si', $_SERVER['QUERY_STRING
$redirect_url = str_replace(['&admin=1', '?admin=1'], '', $redirect_url); $redirect_url = str_replace(['&admin=1', '?admin=1'], '', $redirect_url);
if (!$redirect_url || false !== strpos(urldecode($redirect_url), "\n") || false !== strpos(urldecode($redirect_url), "\r") || false !== strpos(urldecode($redirect_url), ';url')) { if (!$redirect_url || str_contains(urldecode($redirect_url), "\n") || str_contains(urldecode($redirect_url), "\r") || str_contains(urldecode($redirect_url), ';url')) {
$redirect_url = 'index.php'; $redirect_url = 'index.php';
} }

View file

@ -29,7 +29,7 @@ class IPHelper extends Ip
public static function anonymizeIP(string $ip): string public static function anonymizeIP(string $ip): string
{ {
$wrappedIPv6 = false; $wrappedIPv6 = false;
if ('[' === substr($ip, 0, 1) && ']' === substr($ip, -1, 1)) { if (str_starts_with($ip, '[') && str_ends_with($ip, ']')) {
$wrappedIPv6 = true; $wrappedIPv6 = true;
$ip = substr($ip, 1, -1); $ip = substr($ip, 1, -1);
} }

View file

@ -169,7 +169,7 @@ class BBCode
private function parse($text): string private function parse($text): string
{ {
// Tag parse // Tag parse
if (strpos($text, '[') === false) { if (!str_contains($text, '[')) {
return $text; return $text;
} }

View file

@ -968,7 +968,7 @@ class SqlDb
$query = "SELECT * FROM $m[1] WHERE $m[2]"; $query = "SELECT * FROM $m[1] WHERE $m[2]";
} }
if (0 === strpos($query, "SELECT")) { if (str_starts_with($query, "SELECT")) {
$html_table = false; $html_table = false;
if ($result = mysqli_query($this->link, "EXPLAIN $query")) { if ($result = mysqli_query($this->link, "EXPLAIN $query")) {

View file

@ -310,7 +310,7 @@ class Template
*/ */
public function assign_block_vars($blockname, $vararray) public function assign_block_vars($blockname, $vararray)
{ {
if (false !== strpos($blockname, '.')) { if (str_contains($blockname, '.')) {
// Nested block. // Nested block.
$blocks = explode('.', $blockname); $blocks = explode('.', $blockname);
$blockcount = \count($blocks) - 1; $blockcount = \count($blocks) - 1;
@ -994,7 +994,7 @@ class Template
$this->vars['LANG'] ??= $bb_cfg['default_lang']; $this->vars['LANG'] ??= $bb_cfg['default_lang'];
// adding current template // adding current template
$tpl = $this->root . '/'; $tpl = $this->root . '/';
if (0 === strpos($tpl, './')) { if (str_starts_with($tpl, './')) {
$tpl = substr($tpl, 2, \strlen($tpl)); $tpl = substr($tpl, 2, \strlen($tpl));
} }
$this->vars['TEMPLATE'] ??= $tpl; $this->vars['TEMPLATE'] ??= $tpl;