Skip to content

Commit

Permalink
Merge branch '2.1.x' into 2.2.x
Browse files Browse the repository at this point in the history
Closes gh-20432
  • Loading branch information
mbhave committed Mar 9, 2020
2 parents 1fdb083 + 06d870b commit a27e145
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
*
* @author Dave Syer
* @author Andy Wilkinson
* @author Madhura Bhave
* @since 1.3.0
*/
public class CloudFoundryVcapEnvironmentPostProcessor
Expand Down Expand Up @@ -231,19 +230,7 @@ private String getPropertyName(String path, String key) {
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
*
* @author Dave Syer
* @author Andy Wilkinson
* @author Hans Schulz
* @author Madhura Bhave
*/
class CloudFoundryVcapEnvironmentPostProcessorTests {

Expand Down Expand Up @@ -118,26 +116,6 @@ void testServicePropertiesWithoutNA() {
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");
}

@Test
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);
}
Expand Down

0 comments on commit a27e145

Please sign in to comment.