diff --git a/docs/src/main/asciidoc/spring-cloud-config.adoc b/docs/src/main/asciidoc/spring-cloud-config.adoc index 6f3db748..6213d77f 100644 --- a/docs/src/main/asciidoc/spring-cloud-config.adoc +++ b/docs/src/main/asciidoc/spring-cloud-config.adoc @@ -150,10 +150,10 @@ working copy as a cache. This repository implementation maps the `{label}` parameter of the HTTP resource to a git label (commit id, branch name or tag). If the git branch or tag name contains a slash ("/") then the label in the -HTTP URL should be specified with the special string "(\_)" instead (to +HTTP URL should be specified with the special string "(_)" instead (to avoid ambiguity with other URL paths). For example, if the label is `foo/bar`, replacing the slash would result in a label that looks like -`foo(_)bar`. The inclusion of the special string "(\_)" can also be +`foo(_)bar`. The inclusion of the special string "(_)" can also be applied to the `{application}` parameter. Be careful with the brackets in the URL if you are using a command line client like curl (e.g. escape them from the shell with quotes ''). @@ -179,7 +179,7 @@ spring: or a "one repo per profile" policy using a similar pattern but with `{profile}`. -Additionally, using the special string "(\_)" within your +Additionally, using the special string "(_)" within your `{application}` parameters can enable support for multiple organizations (for example): @@ -194,7 +194,7 @@ spring: ---- where `{application}` is provided at request time in the format -"organization(\_)application". +"organization(_)application". ===== Pattern Matching and Multiple Repositories diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java index 7d040c33..3d6c0e3a 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java @@ -99,6 +99,11 @@ public class EnvironmentController { @RequestMapping("/{name}/{profiles}/{label:.*}") public Environment labelled(@PathVariable String name, @PathVariable String profiles, @PathVariable String label) { + if (name != null && name.contains("(_)")) { + // "(_)" is uncommon in a git repo name, but "/" cannot be matched + // by Spring MVC + name = name.replace("(_)", "/"); + } if (label != null && label.contains("(_)")) { // "(_)" is uncommon in a git branch name, but "/" cannot be matched // by Spring MVC diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java index 96001840..238e1228 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java @@ -139,6 +139,15 @@ public class EnvironmentControllerIntegrationTests { .andExpect(MockMvcResultMatchers.content().string(Matchers.containsString("\"propertySources\":"))); } + @Test + public void environmentWithApplicationContainingSlash() throws Exception { + Mockito.when(this.repository.findOne("foo/app", "default", null)) + .thenReturn(new Environment("foo/app", "default")); + this.mvc.perform(MockMvcRequestBuilders.get("/foo(_)app/default")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().string(Matchers.containsString("\"propertySources\":"))); + } + @Configuration @EnableWebMvc @Import(PropertyPlaceholderAutoConfiguration.class)