Merge branch '3.1.x'

This commit is contained in:
Ryan Baxter
2023-03-08 14:29:00 -05:00
2 changed files with 28 additions and 3 deletions

View File

@@ -481,6 +481,7 @@ public class EnvironmentController {
private String getKey() {
// Consider initial value or previous char '.' or '['
int start = this.currentPos + 1;
int openingBracketPosition = -1;
for (int i = start; i < this.propertyKey.length(); i++) {
char currentChar = this.propertyKey.charAt(i);
if (currentChar == '.') {
@@ -489,9 +490,20 @@ public class EnvironmentController {
break;
}
else if (currentChar == '[') {
this.valueType = NodeType.ARRAY;
this.currentPos = i;
break;
openingBracketPosition = i;
}
else if (currentChar == ']') {
String bracketContents = this.propertyKey.substring(openingBracketPosition + 1, i);
try {
Integer.parseInt(bracketContents);
this.valueType = NodeType.ARRAY;
this.currentPos = openingBracketPosition;
break;
}
catch (NumberFormatException e) {
// This means the key contains a [ and a ] but the contents were
// not an integer so it's not an array
}
}
}
// If there's no delimiter then it's a key of a leaf

View File

@@ -182,6 +182,19 @@ class EnvironmentControllerTests {
assertThat(yaml).isEqualTo("a:\n b:\n - c\n - d\n");
}
@Test
public void yamlWithBrackets() throws Exception {
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("a.test", "e");
map.put("a.b[hello]", "c");
map.put("a.b[world]", "d");
map.put("a.b[world]d", "f");
this.environment.add(new PropertySource("one", map));
when(this.repository.findOne("foo", "bar", null, false)).thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
assertThat(yaml).isEqualTo("a:\n test: e\n b[hello]: c\n b[world]: d\n b[world]d: f\n");
}
@Test
public void arrayOverridenInEnvironment() throws Exception {
// Add original values first source