Skip to content

Commit 497a863

Browse files
Merge pull request #44476 from nextcloud/backport/44276/stable25
[stable25] fix(config): Make sure user keys are strings
2 parents 2dda075 + ff4c01b commit 497a863

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

lib/private/AllConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public function getUserValue($userId, $appName, $key, $default = '') {
334334
public function getUserKeys($userId, $appName) {
335335
$data = $this->getAllUserValues($userId);
336336
if (isset($data[$appName])) {
337-
return array_keys($data[$appName]);
337+
return array_map('strval', array_keys($data[$appName]));
338338
} else {
339339
return [];
340340
}

tests/lib/AllConfigTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,31 @@ public function testGetUserKeys() {
278278
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
279279
}
280280

281+
public function testGetUserKeysAllInts() {
282+
$config = $this->getConfig();
283+
284+
// preparation - add something to the database
285+
$data = [
286+
['userFetch', 'appFetch1', '123', 'value'],
287+
['userFetch', 'appFetch1', '456', 'value'],
288+
];
289+
foreach ($data as $entry) {
290+
$this->connection->executeUpdate(
291+
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
292+
'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
293+
$entry
294+
);
295+
}
296+
297+
$value = $config->getUserKeys('userFetch', 'appFetch1');
298+
$this->assertEquals(['123', '456'], $value);
299+
$this->assertIsString($value[0]);
300+
$this->assertIsString($value[1]);
301+
302+
// cleanup
303+
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
304+
}
305+
281306
public function testGetUserValueDefault() {
282307
$config = $this->getConfig();
283308

0 commit comments

Comments
 (0)