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 cf64eeed..06eb7ff9 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 @@ -104,12 +104,14 @@ public class EnvironmentController { this.acceptEmpty = acceptEmpty; } - @GetMapping(path = "/{name}/{profiles:[^-]+}", produces = MediaType.APPLICATION_JSON_VALUE) + @GetMapping(path = "/{name}/{profiles:(?!.*\\b(?:ya?ml|properties|json)\\b).*}", + produces = MediaType.APPLICATION_JSON_VALUE) public Environment defaultLabel(@PathVariable String name, @PathVariable String profiles) { return getEnvironment(name, profiles, null, false); } - @GetMapping(path = "/{name}/{profiles:[^-]+}", produces = EnvironmentMediaType.V2_JSON) + @GetMapping(path = "/{name}/{profiles:(?!.*\\b(?:ya?ml|properties|json)\\b).*}", + produces = EnvironmentMediaType.V2_JSON) public Environment defaultLabelIncludeOrigin(@PathVariable String name, @PathVariable String profiles) { return getEnvironment(name, profiles, null, true); } 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 9f7fe93b..22523fe5 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 @@ -77,6 +77,16 @@ class EnvironmentControllerIntegrationTests { verify(this.repository).findOne("foo", "default", null, false); } + @Test + public void profileWithDash() throws Exception { + Environment dashEnvironment = new Environment("foo", "dev-db"); + dashEnvironment.add(new PropertySource("foo", new HashMap<>())); + when(this.repository.findOne("foo", "dev-db", null, false)).thenReturn(dashEnvironment); + this.mvc.perform(MockMvcRequestBuilders.get("/foo/dev-db")) + .andExpect(MockMvcResultMatchers.status().isOk()); + verify(this.repository).findOne("foo", "dev-db", null, false); + } + @Test public void propertiesNoLabel() throws Exception { when(this.repository.findOne("foo", "default", null, false)).thenReturn(this.environment);