Skip to content

Commit

Permalink
Handle JSON keys containing a dot from CF environment as a single pat…
Browse files Browse the repository at this point in the history
…h segment

See spring-projectsgh-18915
  • Loading branch information
schulzh authored and mbhave committed Feb 11, 2020
1 parent b0aba9e commit 6828a15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ private String getPropertyName(String path, String key) {
if (key.startsWith("[")) {
return path + key;
}
if (key.contains(".")) {
return path + "[" + key + "]";
}
return path + "." + key;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ public 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");
}

private String getProperty(String key) {
return this.context.getEnvironment().getProperty(key);
}
Expand Down

0 comments on commit 6828a15

Please sign in to comment.