diff --git a/apps/files/lib/Service/UserConfig.php b/apps/files/lib/Service/UserConfig.php index 0abcfb2a6add7..2ef7a3782f029 100644 --- a/apps/files/lib/Service/UserConfig.php +++ b/apps/files/lib/Service/UserConfig.php @@ -115,7 +115,12 @@ public function setConfig(string $key, $value): void { throw new \InvalidArgumentException('Unknown config key'); } - if (!in_array($value, $this->getAllowedConfigValues($key))) { + $isBoolValue = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); + if ($isBoolValue !== null) { + $value = $isBoolValue; + } + + if (!in_array($value, $this->getAllowedConfigValues($key), true)) { throw new \InvalidArgumentException('Invalid config value'); } diff --git a/apps/files/tests/Service/UserConfigTest.php b/apps/files/tests/Service/UserConfigTest.php index c4ef345180f33..0161796d36002 100644 --- a/apps/files/tests/Service/UserConfigTest.php +++ b/apps/files/tests/Service/UserConfigTest.php @@ -112,12 +112,29 @@ public function testThrowsInvalidArgumentExceptionForUnknownConfigKey(): void { $userConfig->setConfig('unknown_key', true); } - public function testSetsConfigSuccessfully(): void { + public static function validBoolConfigValues(): array { + return [ + ['true', '1'], + ['false', '0'], + ['1', '1'], + ['0', '0'], + ['yes', '1'], + ['no', '0'], + [true, '1'], + [false, '0'], + ]; + } + + /** + * @dataProvider validBoolConfigValues + */ + public function testSetsConfigWithBooleanValuesSuccessfully($boolValue, $expectedValue): void { $this->configMock->expects($this->once()) ->method('setUserValue') - ->with($this->userUID, Application::APP_ID, 'crop_image_previews', '1'); + ->with($this->userUID, Application::APP_ID, 'crop_image_previews', $expectedValue); + $userConfig = new UserConfig($this->configMock, $this->userSessionMock); - $userConfig->setConfig('crop_image_previews', true); + $userConfig->setConfig('crop_image_previews', $boolValue); } public function testGetsConfigsWithDefaultValuesSuccessfully(): void {