From 876522204e364bdb1a2a4bdc52b137949d235d82 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Mon, 18 Mar 2024 14:51:35 +0100 Subject: [PATCH] fix(config): Make sure user keys are strings Signed-off-by: Christoph Wurst --- lib/private/AllConfig.php | 2 +- tests/lib/AllConfigTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php index 40a52b16628b3..38b1845aae53c 100644 --- a/lib/private/AllConfig.php +++ b/lib/private/AllConfig.php @@ -333,7 +333,7 @@ public function getUserValue($userId, $appName, $key, $default = '') { public function getUserKeys($userId, $appName) { $data = $this->getUserValues($userId); if (isset($data[$appName])) { - return array_keys($data[$appName]); + return array_map('strval', array_keys($data[$appName])); } else { return []; } diff --git a/tests/lib/AllConfigTest.php b/tests/lib/AllConfigTest.php index b0b0b7eff8b50..31ad2c7f3088c 100644 --- a/tests/lib/AllConfigTest.php +++ b/tests/lib/AllConfigTest.php @@ -278,6 +278,31 @@ public function testGetUserKeys() { $this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`'); } + public function testGetUserKeysAllInts() { + $config = $this->getConfig(); + + // preparation - add something to the database + $data = [ + ['userFetch', 'appFetch1', '123', 'value'], + ['userFetch', 'appFetch1', '456', 'value'], + ]; + foreach ($data as $entry) { + $this->connection->executeUpdate( + 'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' . + '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)', + $entry + ); + } + + $value = $config->getUserKeys('userFetch', 'appFetch1'); + $this->assertEquals(['123', '456'], $value); + $this->assertIsString($value[0]); + $this->assertIsString($value[1]); + + // cleanup + $this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`'); + } + public function testGetUserValueDefault() { $config = $this->getConfig();