From 06d870bdd020dd118de098b99996b28b26910233 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Mon, 9 Mar 2020 15:56:48 -0700 Subject: [PATCH] Do not wrap CF JSON Keys containing special characters This reverts commit 6828a15d31ac7d1ca1bfd560cfa05c393b3b7128. The commit has been reverted as it breaks backwards compatiblity. Fixes gh-20343 --- ...udFoundryVcapEnvironmentPostProcessor.java | 13 ----------- ...ndryVcapEnvironmentPostProcessorTests.java | 22 ------------------- 2 files changed, 35 deletions(-) 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 d79c4f9f5a1..ee60ef6fb70 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 @@ -87,7 +87,6 @@ import org.springframework.util.StringUtils; * * @author Dave Syer * @author Andy Wilkinson - * @author Madhura Bhave * @since 1.3.0 */ public class CloudFoundryVcapEnvironmentPostProcessor @@ -231,19 +230,7 @@ public class CloudFoundryVcapEnvironmentPostProcessor if (key.startsWith("[")) { return path + key; } - if (shouldWrap(key)) { - return path + "[" + key + "]"; - } return path + "." + key; } - private boolean shouldWrap(String key) { - for (char ch : key.toCharArray()) { - if (!Character.isLowerCase(ch) && !Character.isDigit(ch) && ch != '-') { - return true; - } - } - return false; - } - } 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 362930c2c77..808a86eeee9 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 @@ -30,8 +30,6 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Dave Syer * @author Andy Wilkinson - * @author Hans Schulz - * @author Madhura Bhave */ public class CloudFoundryVcapEnvironmentPostProcessorTests { @@ -119,26 +117,6 @@ public class CloudFoundryVcapEnvironmentPostProcessorTests { assertThat(getProperty("vcap.services.mysql.credentials.port")).isEqualTo("3306"); } - @Test - public 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"); - } - - @Test - public void testServicePropertiesContainingKeysWithUpperCaseAndNonAlphaNumericCharacters() { - TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, - "VCAP_SERVICES={\"user-provided\":[{\"name\":\"test\",\"label\":\"test-label\"," - + "\"credentials\":{\"My-Key\":\"some-value\", \"foo@\":\"bar\"}}]}"); - this.initializer.postProcessEnvironment(this.context.getEnvironment(), null); - assertThat(getProperty("vcap.services.test.credentials[My-Key]")).isEqualTo("some-value"); - assertThat(getProperty("vcap.services.test.credentials[foo@]")).isEqualTo("bar"); - } - private String getProperty(String key) { return this.context.getEnvironment().getProperty(key); }