Skip to content

Commit 6828a15

Browse files
schulzhmbhave
authored andcommitted
Handle JSON keys containing a dot from CF environment as a single path segment
See gh-18915
1 parent b0aba9e commit 6828a15

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ private String getPropertyName(String path, String key) {
230230
if (key.startsWith("[")) {
231231
return path + key;
232232
}
233+
if (key.contains(".")) {
234+
return path + "[" + key + "]";
235+
}
233236
return path + "." + key;
234237
}
235238

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/cloud/cloudfoundry/CloudFoundryVcapEnvironmentPostProcessorTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ public void testServicePropertiesWithoutNA() {
117117
assertThat(getProperty("vcap.services.mysql.credentials.port")).isEqualTo("3306");
118118
}
119119

120+
@Test
121+
void testServicePropertiesContainingKeysWithDot() {
122+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
123+
"VCAP_SERVICES={\"user-provided\":[{\"name\":\"test\",\"label\":\"test-label\","
124+
+ "\"credentials\":{\"key.with.dots\":\"some-value\"}}]}");
125+
this.initializer.postProcessEnvironment(this.context.getEnvironment(), null);
126+
assertThat(getProperty("vcap.services.test.name")).isEqualTo("test");
127+
assertThat(getProperty("vcap.services.test.credentials[key.with.dots]")).isEqualTo("some-value");
128+
}
129+
120130
private String getProperty(String key) {
121131
return this.context.getEnvironment().getProperty(key);
122132
}

0 commit comments

Comments
 (0)