diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java index 587cd0eedc..7fec2ea7b3 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java @@ -230,6 +230,9 @@ public class CloudFoundryVcapEnvironmentPostProcessor if (key.startsWith("[")) { return path + key; } + if (key.contains(".")) { + return path + "[" + key + "]"; + } return path + "." + key; } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/cloud/cloudfoundry/CloudFoundryVcapEnvironmentPostProcessorTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/cloud/cloudfoundry/CloudFoundryVcapEnvironmentPostProcessorTests.java index 1dfc56386c..3293acf56d 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/cloud/cloudfoundry/CloudFoundryVcapEnvironmentPostProcessorTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/cloud/cloudfoundry/CloudFoundryVcapEnvironmentPostProcessorTests.java @@ -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); }