Handle JSON keys containing a dot from CF environment as a single path segment

See gh-18915
pull/20429/head
Hans Schulz 5 years ago committed by Madhura Bhave
parent b0aba9ed67
commit 6828a15d31

@ -230,6 +230,9 @@ public class CloudFoundryVcapEnvironmentPostProcessor
if (key.startsWith("[")) {
return path + key;
}
if (key.contains(".")) {
return path + "[" + key + "]";
}
return path + "." + key;
}

@ -117,6 +117,16 @@ public class CloudFoundryVcapEnvironmentPostProcessorTests {
assertThat(getProperty("vcap.services.mysql.credentials.port")).isEqualTo("3306");
}
@Test
void testServicePropertiesContainingKeysWithDot() {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
"VCAP_SERVICES={\"user-provided\":[{\"name\":\"test\",\"label\":\"test-label\","
+ "\"credentials\":{\"key.with.dots\":\"some-value\"}}]}");
this.initializer.postProcessEnvironment(this.context.getEnvironment(), null);
assertThat(getProperty("vcap.services.test.name")).isEqualTo("test");
assertThat(getProperty("vcap.services.test.credentials[key.with.dots]")).isEqualTo("some-value");
}
private String getProperty(String key) {
return this.context.getEnvironment().getProperty(key);
}

Loading…
Cancel
Save