Skip to content

Commit

Permalink
KTOR-6013 Fix deeply nested keys in MapApplicationConfig::toMap (#3664
Browse files Browse the repository at this point in the history
)

* KTOR-6013 Fix deeply nested keys in `MapApplicationConfig::toMap`

https://youtrack.jetbrains.com/issue/KTOR-6013

* Add test
  • Loading branch information
rsinukov authored Jun 28, 2023
1 parent dd58daa commit 38449f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public open class MapApplicationConfig : ApplicationConfig {
map.containsKey(combine(path, "0")) -> key to property(path).getList()
else -> key to configList(path).map { it.toMap() }
}
else -> key to config(path).toMap()
else -> key to config(key).toMap()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ class MapApplicationConfigTest {
config.put("users.0.password", "asd")
config.put("users.1.name", "other")
config.put("users.1.password", "qwe")
config.put("nested.config.value", "a1")

val map = config.toMap()

assertEquals(6, map.size)
assertEquals(7, map.size)
assertEquals("SHA-256", map["hashAlgorithm"])
assertEquals("ktor", map["salt"])
assertEquals(
Expand All @@ -133,5 +134,8 @@ class MapApplicationConfigTest {
assertEquals(listOf("a", "b"), map["values"])
assertEquals(listOf("a", "b", "c"), map["listValues"])
assertEquals(mapOf("value1" to "1", "value2" to "2"), map["data"])

@Suppress("UNCHECKED_CAST")
assertEquals("a1", (map["nested"] as Map<String, Map<String, String>>)["config"]!!["value"])
}
}

0 comments on commit 38449f2

Please sign in to comment.