Commit 6828a15d authored by Hans Schulz's avatar Hans Schulz Committed by Madhura Bhave

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

See gh-18915
parent b0aba9ed
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment