浏览代码

Merge pull request #44336 from nextcloud/backport/44276/stable28

[stable28] fix(config): Make sure user keys are strings
Joas Schilling 2 月之前
父节点
当前提交
5782313297
共有 2 个文件被更改,包括 26 次插入1 次删除
  1. 1 1
      lib/private/AllConfig.php
  2. 25 0
      tests/lib/AllConfigTest.php

+ 1 - 1
lib/private/AllConfig.php

@@ -334,7 +334,7 @@ class AllConfig implements IConfig {
 	public function getUserKeys($userId, $appName) {
 		$data = $this->getAllUserValues($userId);
 		if (isset($data[$appName])) {
-			return array_keys($data[$appName]);
+			return array_map('strval', array_keys($data[$appName]));
 		} else {
 			return [];
 		}

+ 25 - 0
tests/lib/AllConfigTest.php

@@ -277,6 +277,31 @@ class AllConfigTest extends \Test\TestCase {
 		$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();