mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Use str_contains and similar instead of strpos
This commit is contained in:
parent
508de10191
commit
1dbf36b86b
16 changed files with 18 additions and 19 deletions
|
@ -1,4 +1,2 @@
|
||||||
framework:
|
framework:
|
||||||
test: true
|
test: true
|
||||||
session:
|
|
||||||
storage_id: session.storage.mock_file
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
>
|
>
|
||||||
<php>
|
<php>
|
||||||
<ini name="error_reporting" value="-1"/>
|
<ini name="error_reporting" value="-1"/>
|
||||||
|
<server name="KERNEL_CLASS" value="App\Kernel"/>
|
||||||
<server name="APP_ENV" value="test" force="true"/>
|
<server name="APP_ENV" value="test" force="true"/>
|
||||||
<server name="SHELL_VERBOSITY" value="-1"/>
|
<server name="SHELL_VERBOSITY" value="-1"/>
|
||||||
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
|
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
|
||||||
|
|
|
@ -62,7 +62,7 @@ class RedirectController extends AbstractController
|
||||||
|
|
||||||
//If either mod_rewrite is not enabled or the index.php version is enforced, add index.php to the string
|
//If either mod_rewrite is not enabled or the index.php version is enforced, add index.php to the string
|
||||||
if (($this->enforce_index_php || !$this->checkIfModRewriteAvailable())
|
if (($this->enforce_index_php || !$this->checkIfModRewriteAvailable())
|
||||||
&& false === strpos($new_url, 'index.php')) {
|
&& !str_contains($new_url, 'index.php')) {
|
||||||
//Like Request::getUriForPath only with index.php
|
//Like Request::getUriForPath only with index.php
|
||||||
$new_url = $request->getSchemeAndHttpHost().$request->getBaseUrl().'/index.php/'.$locale.$request->getPathInfo();
|
$new_url = $request->getSchemeAndHttpHost().$request->getBaseUrl().'/index.php/'.$locale.$request->getPathInfo();
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ class SelectAPIController extends AbstractController
|
||||||
//Remove the data-* prefix for each key
|
//Remove the data-* prefix for each key
|
||||||
$data = array_combine(
|
$data = array_combine(
|
||||||
array_map(static function ($key) {
|
array_map(static function ($key) {
|
||||||
if (strpos($key, 'data-') === 0) {
|
if (str_starts_with($key, 'data-')) {
|
||||||
return substr($key, 5);
|
return substr($key, 5);
|
||||||
}
|
}
|
||||||
return $key;
|
return $key;
|
||||||
|
|
|
@ -417,7 +417,7 @@ abstract class Attachment extends AbstractNamedDBElement
|
||||||
{
|
{
|
||||||
//Only set if the URL is not empty
|
//Only set if the URL is not empty
|
||||||
if (!empty($url)) {
|
if (!empty($url)) {
|
||||||
if (false !== strpos($url, '%BASE%') || false !== strpos($url, '%MEDIA%')) {
|
if (str_contains($url, '%BASE%') || str_contains($url, '%MEDIA%')) {
|
||||||
throw new InvalidArgumentException('You can not reference internal files via the url field! But nice try!');
|
throw new InvalidArgumentException('You can not reference internal files via the url field! But nice try!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,7 @@ abstract class AbstractLogEntry extends AbstractDBElement
|
||||||
*/
|
*/
|
||||||
public function isCLIEntry(): bool
|
public function isCLIEntry(): bool
|
||||||
{
|
{
|
||||||
return strpos($this->username, '!!!CLI ') === 0;
|
return str_starts_with($this->username, '!!!CLI ');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -128,7 +128,7 @@ final class PermissionData implements \JsonSerializable
|
||||||
public function isPermissionSet(string $permission, string $operation): bool
|
public function isPermissionSet(string $permission, string $operation): bool
|
||||||
{
|
{
|
||||||
//We cannot access metadata via normal permission data
|
//We cannot access metadata via normal permission data
|
||||||
if (strpos($permission, '$') !== false) {
|
if (str_contains($permission, '$')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ final class PasswordChangeNeededSubscriber implements EventSubscriberInterface
|
||||||
|
|
||||||
/* Dont redirect tree endpoints, as this would cause trouble and creates multiple flash
|
/* Dont redirect tree endpoints, as this would cause trouble and creates multiple flash
|
||||||
warnigs for one page reload */
|
warnigs for one page reload */
|
||||||
if (false !== strpos($request->getUri(), '/tree/')) {
|
if (str_contains($request->getUri(), '/tree/')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,7 @@ final class SIUnitType extends AbstractType implements DataMapperInterface
|
||||||
|
|
||||||
//Check if we need to make this thing small
|
//Check if we need to make this thing small
|
||||||
if (isset($options['attr']['class'])) {
|
if (isset($options['attr']['class'])) {
|
||||||
$view->vars['sm'] = false !== strpos($options['attr']['class'], 'form-control-sm');
|
$view->vars['sm'] = str_contains($options['attr']['class'], 'form-control-sm');
|
||||||
}
|
}
|
||||||
|
|
||||||
$view->vars['unit'] = $options['unit'];
|
$view->vars['unit'] = $options['unit'];
|
||||||
|
|
|
@ -110,7 +110,7 @@ class LabelResponse extends Response
|
||||||
*/
|
*/
|
||||||
public function setContentDisposition(string $disposition, string $filename, string $filenameFallback = ''): self
|
public function setContentDisposition(string $disposition, string $filename, string $filenameFallback = ''): self
|
||||||
{
|
{
|
||||||
if ('' === $filenameFallback && (!preg_match('/^[\x20-\x7e]*$/', $filename) || false !== strpos($filename, '%'))) {
|
if ('' === $filenameFallback && (!preg_match('/^[\x20-\x7e]*$/', $filename) || str_contains($filename, '%'))) {
|
||||||
$encoding = mb_detect_encoding($filename, null, true) ?: '8bit';
|
$encoding = mb_detect_encoding($filename, null, true) ?: '8bit';
|
||||||
|
|
||||||
for ($i = 0, $filenameLength = mb_strlen($filename, $encoding); $i < $filenameLength; ++$i) {
|
for ($i = 0, $filenameLength = mb_strlen($filename, $encoding); $i < $filenameLength; ++$i) {
|
||||||
|
|
|
@ -134,7 +134,7 @@ class AttachmentPathResolver
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
|
||||||
//When path is a footprint we have to first run the string through our lecagy german mapping functions
|
//When path is a footprint we have to first run the string through our lecagy german mapping functions
|
||||||
if (strpos($placeholder_path, '%FOOTPRINTS%') !== false) {
|
if (str_contains($placeholder_path, '%FOOTPRINTS%')) {
|
||||||
$placeholder_path = $this->convertOldFootprintPath($placeholder_path);
|
$placeholder_path = $this->convertOldFootprintPath($placeholder_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ class AttachmentPathResolver
|
||||||
}
|
}
|
||||||
|
|
||||||
//Path is invalid if path is directory traversal
|
//Path is invalid if path is directory traversal
|
||||||
if (false !== strpos($placeholder_path, '..')) {
|
if (str_contains($placeholder_path, '..')) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ class AttachmentURLGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
//Our absolute path must begin with public path, or we can not use it for asset pathes.
|
//Our absolute path must begin with public path, or we can not use it for asset pathes.
|
||||||
if (0 !== strpos($absolute_path, $public_path)) {
|
if (!str_starts_with($absolute_path, $public_path)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ class FileTypeFilterTools
|
||||||
}
|
}
|
||||||
|
|
||||||
//Convert *.jpg to .jpg
|
//Convert *.jpg to .jpg
|
||||||
if (0 === strpos($element, '*.')) {
|
if (str_starts_with($element, '*.')) {
|
||||||
$element = str_replace('*.', '.', $element);
|
$element = str_replace('*.', '.', $element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ class FileTypeFilterTools
|
||||||
$element = 'video/*';
|
$element = 'video/*';
|
||||||
} elseif ('audio' === $element || 'audio/' === $element) {
|
} elseif ('audio' === $element || 'audio/' === $element) {
|
||||||
$element = 'audio/*';
|
$element = 'audio/*';
|
||||||
} elseif (!preg_match('#^[-\w.]+/[-\w.*]+#', $element) && 0 !== strpos($element, '.')) {
|
} elseif (!preg_match('#^[-\w.]+/[-\w.*]+#', $element) && !str_starts_with($element, '.')) {
|
||||||
//Convert jpg to .jpg
|
//Convert jpg to .jpg
|
||||||
$element = '.'.$element;
|
$element = '.'.$element;
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ class FileTypeFilterTools
|
||||||
|
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
$element = trim($element);
|
$element = trim($element);
|
||||||
if (0 === strpos($element, '.')) {
|
if (str_starts_with($element, '.')) {
|
||||||
//We found an explicit specified file extension -> add it to list
|
//We found an explicit specified file extension -> add it to list
|
||||||
$extensions[] = substr($element, 1);
|
$extensions[] = substr($element, 1);
|
||||||
} elseif ('image/*' === $element) {
|
} elseif ('image/*' === $element) {
|
||||||
|
|
|
@ -79,7 +79,7 @@ final class BarcodeGenerator
|
||||||
$repr = 'data:';
|
$repr = 'data:';
|
||||||
|
|
||||||
$repr .= $mime;
|
$repr .= $mime;
|
||||||
if (0 === strpos($mime, 'text/')) {
|
if (str_starts_with($mime, 'text/')) {
|
||||||
$repr .= ','.rawurlencode($data);
|
$repr .= ','.rawurlencode($data);
|
||||||
} else {
|
} else {
|
||||||
$repr .= ';base64,'.base64_encode($data);
|
$repr .= ';base64,'.base64_encode($data);
|
||||||
|
|
|
@ -130,7 +130,7 @@ class TreeViewGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
//Translate text if text starts with $$
|
//Translate text if text starts with $$
|
||||||
if (0 === strpos($item->getText(), '$$')) {
|
if (str_starts_with($item->getText(), '$$')) {
|
||||||
$item->setText($this->translator->trans(substr($item->getText(), 2)));
|
$item->setText($this->translator->trans(substr($item->getText(), 2)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,7 +215,7 @@ class PermissionManager
|
||||||
//Set every op listed in also Set
|
//Set every op listed in also Set
|
||||||
foreach ($op['alsoSet'] as $set_also) {
|
foreach ($op['alsoSet'] as $set_also) {
|
||||||
//If the alsoSet value contains a dot then we set the operation of another permission
|
//If the alsoSet value contains a dot then we set the operation of another permission
|
||||||
if (false !== strpos($set_also, '.')) {
|
if (str_contains($set_also, '.')) {
|
||||||
[$set_perm, $set_op] = explode('.', $set_also);
|
[$set_perm, $set_op] = explode('.', $set_also);
|
||||||
} else {
|
} else {
|
||||||
//Else we set the operation of the same permission
|
//Else we set the operation of the same permission
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue