From 5194c38b64cc30efc128cb0006cc5400f95ab80e Mon Sep 17 00:00:00 2001 From: Anna Larch Date: Wed, 27 May 2026 00:02:38 +0200 Subject: [PATCH] fix: guard against null keys/aliases to fix PHP 8.4 deprecation warnings - CappedMemoryCache: return early from get/hasKey/remove when key is null - QueryBuilder: coerce null alias to '' in join methods only, so DBAL does not receive null as an array key; quoteAlias() itself is unchanged so from() keeps its null-alias behaviour - user_ldap Access: guard null sndAttribute before using as array offset Signed-off-by: Anna Larch AI-Assisted-By: Claude Sonnet 4.6 --- apps/user_ldap/lib/Access.php | 2 +- lib/private/DB/QueryBuilder/QueryBuilder.php | 8 ++++---- lib/public/Cache/CappedMemoryCache.php | 9 +++++++++ tests/lib/DB/QueryBuilder/QueryBuilderTest.php | 6 +++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php index 09fd099b7506a..04546937b1029 100644 --- a/apps/user_ldap/lib/Access.php +++ b/apps/user_ldap/lib/Access.php @@ -703,7 +703,7 @@ private function ldap2NextcloudNames(array $ldapObjects, bool $isUsers): array { if (is_null($nameByLDAP)) { continue; } - $sndName = $ldapObject[$sndAttribute][0] ?? ''; + $sndName = $sndAttribute !== null ? ($ldapObject[$sndAttribute][0] ?? '') : ''; $this->applyUserDisplayName($ncName, $nameByLDAP, $sndName); } elseif ($nameByLDAP !== null) { $this->cacheGroupDisplayName($ncName, $nameByLDAP); diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php index 30e85675a75dc..7719703e2c2a0 100644 --- a/lib/private/DB/QueryBuilder/QueryBuilder.php +++ b/lib/private/DB/QueryBuilder/QueryBuilder.php @@ -725,7 +725,7 @@ public function join($fromAlias, $join, $alias, $condition = null) { $this->queryBuilder->join( $this->quoteAlias($fromAlias), $this->getTableName($join), - $this->quoteAlias($alias), + $this->quoteAlias($alias) ?? '', $condition ); @@ -754,7 +754,7 @@ public function innerJoin($fromAlias, $join, $alias, $condition = null) { $this->queryBuilder->innerJoin( $this->quoteAlias($fromAlias), $this->getTableName($join), - $this->quoteAlias($alias), + $this->quoteAlias($alias) ?? '', $condition ); @@ -783,7 +783,7 @@ public function leftJoin($fromAlias, $join, $alias, $condition = null) { $this->queryBuilder->leftJoin( $this->quoteAlias($fromAlias), $this->getTableName($join), - $this->quoteAlias($alias), + $this->quoteAlias($alias) ?? '', $condition ); @@ -812,7 +812,7 @@ public function rightJoin($fromAlias, $join, $alias, $condition = null) { $this->queryBuilder->rightJoin( $this->quoteAlias($fromAlias), $this->getTableName($join), - $this->quoteAlias($alias), + $this->quoteAlias($alias) ?? '', $condition ); diff --git a/lib/public/Cache/CappedMemoryCache.php b/lib/public/Cache/CappedMemoryCache.php index cbffece2c0fa9..49e06c6f90b65 100644 --- a/lib/public/Cache/CappedMemoryCache.php +++ b/lib/public/Cache/CappedMemoryCache.php @@ -37,6 +37,9 @@ public function __construct(int $capacity = 512) { */ #[\Override] public function hasKey($key): bool { + if ($key === null) { + return false; + } return isset($this->cache[$key]); } @@ -46,6 +49,9 @@ public function hasKey($key): bool { */ #[\Override] public function get($key) { + if ($key === null) { + return null; + } return $this->cache[$key] ?? null; } @@ -73,6 +79,9 @@ public function set($key, $value, $ttl = 0): bool { */ #[\Override] public function remove($key): bool { + if ($key === null) { + return false; + } unset($this->cache[$key]); return true; } diff --git a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php index 0014ce86420dc..4c57a652ba4b6 100644 --- a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php @@ -532,7 +532,7 @@ public static function dataJoin(): array { return [ [ 'd1', 'data2', null, null, - ['`d1`' => [['joinType' => 'inner', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => null, 'joinCondition' => null]]], + ['`d1`' => [['joinType' => 'inner', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => '', 'joinCondition' => null]]], '`*PREFIX*data1` `d1` INNER JOIN `*PREFIX*data2` ' ], [ @@ -613,7 +613,7 @@ public static function dataLeftJoin(): array { return [ [ 'd1', 'data2', null, null, - ['`d1`' => [['joinType' => 'left', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => null, 'joinCondition' => null]]], + ['`d1`' => [['joinType' => 'left', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => '', 'joinCondition' => null]]], '`*PREFIX*data1` `d1` LEFT JOIN `*PREFIX*data2` ' ], [ @@ -663,7 +663,7 @@ public static function dataRightJoin(): array { return [ [ 'd1', 'data2', null, null, - ['`d1`' => [['joinType' => 'right', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => null, 'joinCondition' => null]]], + ['`d1`' => [['joinType' => 'right', 'joinTable' => '`*PREFIX*data2`', 'joinAlias' => '', 'joinCondition' => null]]], '`*PREFIX*data1` `d1` RIGHT JOIN `*PREFIX*data2` ' ], [