mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #60654 from nextcloud/fix/null-safe-strtolower-getvaluebool
fix(config): add null coalescing fallback in getValueBool before strtolower
This commit is contained in:
commit
2fb2f31abd
3 changed files with 18 additions and 11 deletions
|
|
@ -3548,11 +3548,6 @@
|
|||
<code><![CDATA[$CONFIG]]></code>
|
||||
</UndefinedVariable>
|
||||
</file>
|
||||
<file src="lib/private/Config/UserConfig.php">
|
||||
<RedundantCast>
|
||||
<code><![CDATA[(string)$this->getTypedValue($userId, $app, $key, $default ? 'true' : 'false', $lazy, ValueType::BOOL)]]></code>
|
||||
</RedundantCast>
|
||||
</file>
|
||||
<file src="lib/private/Console/Application.php">
|
||||
<NoInterfaceProperties>
|
||||
<code><![CDATA[$this->request->server]]></code>
|
||||
|
|
|
|||
|
|
@ -437,7 +437,15 @@ class AppConfig implements IAppConfig {
|
|||
*/
|
||||
#[\Override]
|
||||
public function getValueBool(string $app, string $key, bool $default = false, bool $lazy = false): bool {
|
||||
$b = strtolower($this->getTypedValue($app, $key, $default ? 'true' : 'false', $lazy, self::VALUE_BOOL));
|
||||
// The explicit (string) cast and ?? null guard defend against a PHP OPcache bug where
|
||||
// values passed by reference across function boundaries can have their type corrupted
|
||||
// (e.g. bool returned as int, or null). Affects PHP 8.x with OPcache enabled; fixed
|
||||
// upstream in https://github.com/php/php-src/pull/21973. Keep until minimum PHP version
|
||||
// is bumped. Psalm sees the declared return type (string) and flags these as redundant.
|
||||
/** @psalm-suppress RedundantCondition, TypeDoesNotContainNull */
|
||||
$value = $this->getTypedValue($app, $key, $default ? 'true' : 'false', $lazy, self::VALUE_BOOL) ?? ($default ? 'true' : 'false');
|
||||
/** @psalm-suppress RedundantCast */
|
||||
$b = strtolower((string)$value);
|
||||
return in_array($b, ['1', 'true', 'yes', 'on']);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -705,11 +705,15 @@ class UserConfig implements IUserConfig {
|
|||
bool $default = false,
|
||||
bool $lazy = false,
|
||||
): bool {
|
||||
// The explicit (string) cast guards against a PHP OPcache bug where values passed
|
||||
// by reference across function boundaries can have their type corrupted (e.g. bool
|
||||
// returned as int). Affects PHP 8.x with OPcache enabled; fixed upstream in
|
||||
// https://github.com/php/php-src/pull/21973. Keep until minimum PHP version is bumped.
|
||||
$b = strtolower((string)$this->getTypedValue($userId, $app, $key, $default ? 'true' : 'false', $lazy, ValueType::BOOL));
|
||||
// The explicit (string) cast and ?? null guard defend against a PHP OPcache bug where
|
||||
// values passed by reference across function boundaries can have their type corrupted
|
||||
// (e.g. bool returned as int, or null). Affects PHP 8.x with OPcache enabled; fixed
|
||||
// upstream in https://github.com/php/php-src/pull/21973. Keep until minimum PHP version
|
||||
// is bumped. Psalm sees the declared return type (string) and flags these as redundant.
|
||||
/** @psalm-suppress RedundantCondition, TypeDoesNotContainNull */
|
||||
$value = $this->getTypedValue($userId, $app, $key, $default ? 'true' : 'false', $lazy, ValueType::BOOL) ?? ($default ? 'true' : 'false');
|
||||
/** @psalm-suppress RedundantCast */
|
||||
$b = strtolower((string)$value);
|
||||
return in_array($b, ['1', 'true', 'yes', 'on']);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue