Browse Source

Merge pull request #38610 from fsamapoor/replace_strpos_calls_in_dav_app

Refactors "strpos" calls in /apps/dav
tags/v28.0.0beta1
Christoph Wurst 9 months ago
parent
commit
9627176a23
No account linked to committer's email address

+ 1
- 1
apps/dav/appinfo/v1/webdav.php View File

@@ -31,7 +31,7 @@
use Psr\Log\LoggerInterface;

// no php execution timeout for webdav
if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
@set_time_limit(0);
}
ignore_user_abort(true);

+ 1
- 1
apps/dav/appinfo/v2/direct.php View File

@@ -27,7 +27,7 @@ declare(strict_types=1);
use \OCA\DAV\Direct\ServerFactory;

// no php execution timeout for webdav
if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
@set_time_limit(0);
}
ignore_user_abort(true);

+ 1
- 1
apps/dav/appinfo/v2/remote.php View File

@@ -22,7 +22,7 @@
*
*/
// no php execution timeout for webdav
if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
@set_time_limit(0);
}
ignore_user_abort(true);

+ 3
- 3
apps/dav/lib/CalDAV/Activity/Backend.php View File

@@ -455,9 +455,9 @@ class Backend {

$action = $action . '_' . $object['type'];

if ($object['type'] === 'todo' && strpos($action, Event::SUBJECT_OBJECT_UPDATE) === 0 && $object['status'] === 'COMPLETED') {
if ($object['type'] === 'todo' && str_starts_with($action, Event::SUBJECT_OBJECT_UPDATE) && $object['status'] === 'COMPLETED') {
$action .= '_completed';
} elseif ($object['type'] === 'todo' && strpos($action, Event::SUBJECT_OBJECT_UPDATE) === 0 && $object['status'] === 'NEEDS-ACTION') {
} elseif ($object['type'] === 'todo' && str_starts_with($action, Event::SUBJECT_OBJECT_UPDATE) && $object['status'] === 'NEEDS-ACTION') {
$action .= '_needs_action';
}

@@ -491,7 +491,7 @@ class Backend {
],
];

if ($object['type'] === 'event' && strpos($action, Event::SUBJECT_OBJECT_DELETE) === false && $this->appManager->isEnabledForUser('calendar')) {
if ($object['type'] === 'event' && !str_contains($action, Event::SUBJECT_OBJECT_DELETE) && $this->appManager->isEnabledForUser('calendar')) {
$params['object']['link']['object_uri'] = $objectData['uri'];
$params['object']['link']['calendar_uri'] = $calendarData['uri'];
$params['object']['link']['owner'] = $owner;

+ 2
- 2
apps/dav/lib/CalDAV/Integration/ExternalCalendar.php View File

@@ -98,7 +98,7 @@ abstract class ExternalCalendar implements CalDAV\ICalendar, DAV\IProperties {
* @return bool
*/
public static function isAppGeneratedCalendar(string $calendarUri):bool {
return strpos($calendarUri, self::PREFIX) === 0 && substr_count($calendarUri, self::DELIMITER) >= 2;
return str_starts_with($calendarUri, self::PREFIX) && substr_count($calendarUri, self::DELIMITER) >= 2;
}

/**
@@ -126,6 +126,6 @@ abstract class ExternalCalendar implements CalDAV\ICalendar, DAV\IProperties {
* @return bool
*/
public static function doesViolateReservedName(string $calendarUri):bool {
return strpos($calendarUri, self::PREFIX) === 0;
return str_starts_with($calendarUri, self::PREFIX);
}
}

+ 2
- 2
apps/dav/lib/CalDAV/Publishing/PublishPlugin.php View File

@@ -155,8 +155,8 @@ class PublishPlugin extends ServerPlugin {
$path = $request->getPath();

// Only handling xml
$contentType = $request->getHeader('Content-Type');
if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
$contentType = (string) $request->getHeader('Content-Type');
if (!str_contains($contentType, 'application/xml') && !str_contains($contentType, 'text/xml')) {
return;
}


+ 4
- 4
apps/dav/lib/CalDAV/ResourceBooking/AbstractPrincipalBackend.php View File

@@ -160,7 +160,7 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
* @return array
*/
public function getPrincipalByPath($path) {
if (strpos($path, $this->principalPrefix) !== 0) {
if (!str_starts_with($path, $this->principalPrefix)) {
return null;
}
[, $name] = \Sabre\Uri\split($path);
@@ -443,7 +443,7 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
}
$usersGroups = $this->groupManager->getUserGroupIds($user);

if (strpos($uri, 'mailto:') === 0) {
if (str_starts_with($uri, 'mailto:')) {
$email = substr($uri, 7);
$query = $this->db->getQueryBuilder();
$query->select(['id', 'backend_id', 'resource_id', 'email', 'displayname', 'group_restrictions'])
@@ -463,9 +463,9 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
return $this->rowToPrincipal($row)['uri'];
}

if (strpos($uri, 'principal:') === 0) {
if (str_starts_with($uri, 'principal:')) {
$path = substr($uri, 10);
if (strpos($path, $this->principalPrefix) !== 0) {
if (!str_starts_with($path, $this->principalPrefix)) {
return null;
}


+ 3
- 3
apps/dav/lib/CalDAV/Schedule/Plugin.php View File

@@ -310,10 +310,10 @@ EOF;
return null;
}

$isResourceOrRoom = strpos($principalUrl, 'principals/calendar-resources') === 0 ||
strpos($principalUrl, 'principals/calendar-rooms') === 0;
$isResourceOrRoom = str_starts_with($principalUrl, 'principals/calendar-resources') ||
str_starts_with($principalUrl, 'principals/calendar-rooms');

if (strpos($principalUrl, 'principals/users') === 0) {
if (str_starts_with($principalUrl, 'principals/users')) {
[, $userId] = split($principalUrl);
$uri = $this->config->getUserValue($userId, 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI);
$displayName = CalDavBackend::PERSONAL_CALENDAR_NAME;

+ 5
- 5
apps/dav/lib/CardDAV/CardDavBackend.php View File

@@ -1015,7 +1015,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {

// Micro optimisation
// don't loop through
if (strpos($cardData, 'PHOTO:data:') === 0) {
if (str_starts_with($cardData, 'PHOTO:data:')) {
return $cardData;
}

@@ -1024,8 +1024,8 @@ class CardDavBackend implements BackendInterface, SyncSupport {
$cardDataFiltered = [];
$removingPhoto = false;
foreach ($cardDataArray as $line) {
if (strpos($line, 'PHOTO:data:') === 0
&& strpos($line, 'PHOTO:data:image/') !== 0) {
if (str_starts_with($line, 'PHOTO:data:')
&& !str_starts_with($line, 'PHOTO:data:image/')) {
// Filter out PHOTO data of non-images
$removingPhoto = true;
$modified = true;
@@ -1033,7 +1033,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
}

if ($removingPhoto) {
if (strpos($line, ' ') === 0) {
if (str_starts_with($line, ' ')) {
continue;
}
// No leading space means this is a new property
@@ -1133,7 +1133,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
$propertyOr = $query2->expr()->orX();
foreach ($searchProperties as $property) {
if ($escapePattern) {
if ($property === 'EMAIL' && strpos($pattern, ' ') !== false) {
if ($property === 'EMAIL' && str_contains($pattern, ' ')) {
// There can be no spaces in emails
continue;
}

+ 2
- 2
apps/dav/lib/CardDAV/HasPhotoPlugin.php View File

@@ -66,8 +66,8 @@ class HasPhotoPlugin extends ServerPlugin {
return $vcard instanceof VCard
&& $vcard->PHOTO
// Either the PHOTO is a url (doesn't start with data:) or the mimetype has to start with image/
&& (strpos($vcard->PHOTO->getValue(), 'data:') !== 0
|| strpos($vcard->PHOTO->getValue(), 'data:image/') === 0)
&& (!str_starts_with($vcard->PHOTO->getValue(), 'data:')
|| str_starts_with($vcard->PHOTO->getValue(), 'data:image/'))
;
});
}

+ 2
- 2
apps/dav/lib/CardDAV/Integration/ExternalAddressBook.php View File

@@ -91,7 +91,7 @@ abstract class ExternalAddressBook implements IAddressBook, DAV\IProperties {
* @return bool
*/
public static function isAppGeneratedAddressBook(string $uri): bool {
return strpos($uri, self::PREFIX) === 0 && substr_count($uri, self::DELIMITER) >= 2;
return str_starts_with($uri, self::PREFIX) && substr_count($uri, self::DELIMITER) >= 2;
}

/**
@@ -121,6 +121,6 @@ abstract class ExternalAddressBook implements IAddressBook, DAV\IProperties {
* @return bool
*/
public static function doesViolateReservedName(string $uri): bool {
return strpos($uri, self::PREFIX) === 0;
return str_starts_with($uri, self::PREFIX);
}
}

+ 2
- 2
apps/dav/lib/CardDAV/MultiGetExportPlugin.php View File

@@ -61,8 +61,8 @@ class MultiGetExportPlugin extends DAV\ServerPlugin {
}

// Only handling xml
$contentType = $response->getHeader('Content-Type');
if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
$contentType = (string) $response->getHeader('Content-Type');
if (!str_contains($contentType, 'application/xml') && !str_contains($contentType, 'text/xml')) {
return;
}


+ 2
- 2
apps/dav/lib/CardDAV/PhotoCache.php View File

@@ -264,9 +264,9 @@ class PhotoCache {
if (isset($params['TYPE']) || isset($params['MEDIATYPE'])) {
/** @var Parameter $typeParam */
$typeParam = isset($params['TYPE']) ? $params['TYPE'] : $params['MEDIATYPE'];
$type = $typeParam->getValue();
$type = (string) $typeParam->getValue();

if (strpos($type, 'image/') === 0) {
if (str_starts_with($type, 'image/')) {
return $type;
} else {
return 'image/' . strtolower($type);

+ 1
- 1
apps/dav/lib/CardDAV/SyncService.php View File

@@ -157,7 +157,7 @@ class SyncService {
$certPath = $this->getCertPath();
$client->setThrowExceptions(true);

if ($certPath !== '' && strpos($url, 'http://') !== 0) {
if ($certPath !== '' && !str_starts_with($url, 'http://')) {
$client->addCurlSetting(CURLOPT_CAINFO, $this->certPath);
}


+ 1
- 1
apps/dav/lib/CardDAV/SystemAddressbook.php View File

@@ -122,7 +122,7 @@ class SystemAddressbook extends AddressBook {
$children = parent::getChildren();
return array_filter($children, function (Card $child) {
// check only for URIs that begin with Guests:
return strpos($child->getName(), 'Guests:') !== 0;
return !str_starts_with($child->getName(), 'Guests:');
});
}


+ 1
- 1
apps/dav/lib/Comments/CommentNode.php View File

@@ -79,7 +79,7 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {

$methods = get_class_methods($this->comment);
$methods = array_filter($methods, function ($name) {
return strpos($name, 'get') === 0;
return str_starts_with($name, 'get');
});
foreach ($methods as $getter) {
if ($getter === 'getMentions') {

+ 1
- 1
apps/dav/lib/Comments/CommentsPlugin.php View File

@@ -85,7 +85,7 @@ class CommentsPlugin extends ServerPlugin {
*/
public function initialize(Server $server) {
$this->server = $server;
if (strpos($this->server->getRequestUri(), 'comments/') !== 0) {
if (!str_starts_with($this->server->getRequestUri(), 'comments/')) {
return;
}


+ 1
- 1
apps/dav/lib/Connector/Sabre/AnonymousOptionsPlugin.php View File

@@ -54,7 +54,7 @@ class AnonymousOptionsPlugin extends ServerPlugin {
* @return bool
*/
public function isRequestInRoot($path) {
return $path === '' || (is_string($path) && strpos($path, '/') === false);
return $path === '' || (is_string($path) && !str_contains($path, '/'));
}

/**

+ 1
- 1
apps/dav/lib/Connector/Sabre/CachingTree.php View File

@@ -46,7 +46,7 @@ class CachingTree extends Tree {
$path = trim($path, '/');
foreach ($this->cache as $nodePath => $node) {
$nodePath = (string) $nodePath;
if ('' === $path || $nodePath == $path || 0 === strpos($nodePath, $path.'/')) {
if ('' === $path || $nodePath == $path || str_starts_with($nodePath, $path . '/')) {
unset($this->cache[$nodePath]);
}
}

+ 1
- 1
apps/dav/lib/Connector/Sabre/Principal.php View File

@@ -487,7 +487,7 @@ class Principal implements BackendInterface {
$restrictGroups = $this->groupManager->getUserGroupIds($user);
}

if (strpos($uri, 'mailto:') === 0) {
if (str_starts_with($uri, 'mailto:')) {
if ($principalPrefix === 'principals/users') {
$users = $this->userManager->getByEmail(substr($uri, 7));
if (count($users) !== 1) {

+ 1
- 1
apps/dav/lib/Connector/Sabre/PropfindCompressionPlugin.php View File

@@ -61,7 +61,7 @@ class PropfindCompressionPlugin extends ServerPlugin {
return $response;
}

if (strpos($header, 'gzip') !== false) {
if (str_contains($header, 'gzip')) {
$body = $response->getBody();
if (is_string($body)) {
$response->setHeader('Content-Encoding', 'gzip');

+ 1
- 1
apps/dav/lib/DAV/GroupPrincipalBackend.php View File

@@ -288,7 +288,7 @@ class GroupPrincipalBackend implements BackendInterface {
$restrictGroups = $this->groupManager->getUserGroupIds($user);
}

if (strpos($uri, 'principal:principals/groups/') === 0) {
if (str_starts_with($uri, 'principal:principals/groups/')) {
$name = urlencode(substr($uri, 28));
if ($restrictGroups !== false && !\in_array($name, $restrictGroups, true)) {
return null;

+ 1
- 1
apps/dav/lib/DAV/PublicAuth.php View File

@@ -86,7 +86,7 @@ class PublicAuth implements BackendInterface {
private function isRequestPublic(RequestInterface $request) {
$url = $request->getPath();
$matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) {
return strpos($url, $publicUrl, 0) === 0;
return str_starts_with($url, $publicUrl);
});
return !empty($matchingUrls);
}

+ 2
- 2
apps/dav/lib/DAV/Sharing/Plugin.php View File

@@ -127,8 +127,8 @@ class Plugin extends ServerPlugin {
$path = $request->getPath();

// Only handling xml
$contentType = $request->getHeader('Content-Type');
if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
$contentType = (string) $request->getHeader('Content-Type');
if (!str_contains($contentType, 'application/xml') && !str_contains($contentType, 'text/xml')) {
return;
}


+ 2
- 3
apps/dav/lib/Listener/CalendarContactInteractionListener.php View File

@@ -43,7 +43,6 @@ use Sabre\VObject\Property;
use Sabre\VObject\Reader;
use Throwable;
use function strlen;
use function strpos;
use function substr;

class CalendarContactInteractionListener implements IEventListener {
@@ -130,7 +129,7 @@ class CalendarContactInteractionListener implements IEventListener {
// Invalid principal
return;
}
if (strpos($principal, self::URI_USERS) !== 0) {
if (!str_starts_with($principal, self::URI_USERS)) {
// Not a user principal
return;
}
@@ -159,7 +158,7 @@ class CalendarContactInteractionListener implements IEventListener {
}

$mailTo = $attendee->getValue();
if (strpos($mailTo, 'mailto:') !== 0) {
if (!str_starts_with($mailTo, 'mailto:')) {
// Doesn't look like an email
continue;
}

+ 1
- 2
apps/dav/lib/Listener/CalendarDeletionDefaultUpdaterListener.php View File

@@ -31,7 +31,6 @@ use OCP\EventDispatcher\IEventListener;
use OCP\IConfig;
use Psr\Log\LoggerInterface;
use Throwable;
use function strpos;

/**
* @template-implements IEventListener<\OCA\DAV\Events\CalendarDeletedEvent>
@@ -61,7 +60,7 @@ class CalendarDeletionDefaultUpdaterListener implements IEventListener {

try {
$principalUri = $event->getCalendarData()['principaluri'];
if (strpos($principalUri, 'principals/users') !== 0) {
if (!str_starts_with($principalUri, 'principals/users')) {
$this->logger->debug('Default calendar needs no update because the deleted calendar does not belong to a user principal');
return;
}

+ 1
- 1
apps/dav/lib/Server.php View File

@@ -376,7 +376,7 @@ class Server {
private function requestIsForSubtree(array $subTrees): bool {
foreach ($subTrees as $subTree) {
$subTree = trim($subTree, ' /');
if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) {
if (str_starts_with($this->server->getRequestUri(), $subTree . '/')) {
return true;
}
}

Loading…
Cancel
Save