mirror of
https://github.com/lightbend/config.git
synced 2025-01-15 14:50:23 +08:00
Fix index out of bounds error
Fix an array index out of bounds error, which would occur if a complex value was inserted into an empty root in a ConfigDocument.
This commit is contained in:
parent
398406378d
commit
919c46accc
@ -170,7 +170,7 @@ final class ConfigNodeObject extends ConfigNodeComplexValue {
|
||||
|
||||
// If the value we're inserting is a complex value, we'll need to indent it for insertion
|
||||
AbstractConfigNodeValue indentedValue;
|
||||
if (value instanceof ConfigNodeComplexValue) {
|
||||
if (value instanceof ConfigNodeComplexValue && !indentation.isEmpty()) {
|
||||
indentedValue = ((ConfigNodeComplexValue) value).indentText(indentation.get(indentation.size() - 1));
|
||||
} else {
|
||||
indentedValue = value;
|
||||
|
@ -436,6 +436,13 @@ class ConfigDocumentTest extends TestUtils {
|
||||
val configDocument = ConfigDocumentFactory.parseString(origText)
|
||||
|
||||
assertEquals("a : 1", configDocument.withValueText("a", "1").render)
|
||||
|
||||
val mapVal = ConfigValueFactory.fromAnyRef(Map("a" -> 1, "b" -> 2).asJava)
|
||||
assertEquals("a : {\n # hardcoded value\n \"a\" : 1,\n # hardcoded value\n \"b\" : 2\n}",
|
||||
configDocument.withValue("a", mapVal).render)
|
||||
|
||||
val arrayVal = ConfigValueFactory.fromAnyRef(List(1, 2).asJava)
|
||||
assertEquals("a : [\n # hardcoded value\n 1,\n # hardcoded value\n 2\n]", configDocument.withValue("a", arrayVal).render)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user