Skip to content

Commit

Permalink
Merge pull request #44481 from nextcloud/backport/44276/stable23
Browse files Browse the repository at this point in the history
[stable23] fix(config): Make sure user keys are strings
  • Loading branch information
nickvergessen committed Mar 28, 2024
2 parents acc07c8 + 8765222 commit d19ad7f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/private/AllConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand Down
25 changes: 25 additions & 0 deletions tests/lib/AllConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit d19ad7f

Please sign in to comment.