Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable23] fix(config): Make sure user keys are strings #44481

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading