Simplify regex in EnvironmentController (#2132)

This commit is contained in:
woshikid
2022-09-23 21:09:11 +08:00
committed by GitHub
parent 5e162cb8f1
commit 10546f52ab
2 changed files with 4 additions and 4 deletions

View File

@@ -104,13 +104,13 @@ public class EnvironmentController {
this.acceptEmpty = acceptEmpty;
}
@GetMapping(path = "/{name}/{profiles:(?!.*\\b\\.(?:ya?ml|properties|json)\\b).*}",
@GetMapping(path = "/{name}/{profiles:[^\\.]*}",
produces = MediaType.APPLICATION_JSON_VALUE)
public Environment defaultLabel(@PathVariable String name, @PathVariable String profiles) {
return getEnvironment(name, profiles, null, false);
}
@GetMapping(path = "/{name}/{profiles:(?!.*\\b\\.(?:ya?ml|properties|json)\\b).*}",
@GetMapping(path = "/{name}/{profiles:[^\\.]*}",
produces = EnvironmentMediaType.V2_JSON)
public Environment defaultLabelIncludeOrigin(@PathVariable String name, @PathVariable String profiles) {
return getEnvironment(name, profiles, null, true);

View File

@@ -643,11 +643,11 @@ class EnvironmentControllerTests {
@Test
public void handleEnvironmentException() throws Exception {
when(EnvironmentControllerTests.this.repository.findOne(eq("exception"), eq("bad_syntax.ext"), any(),
when(EnvironmentControllerTests.this.repository.findOne(eq("exception"), eq("bad_syntax"), any(),
eq(false)))
.thenThrow(new FailedToConstructEnvironmentException("Cannot construct",
new RuntimeException("underlier")));
MvcResult result = this.mvc.perform(MockMvcRequestBuilders.get("/exception/bad_syntax.ext"))
MvcResult result = this.mvc.perform(MockMvcRequestBuilders.get("/exception/bad_syntax"))
.andExpect(MockMvcResultMatchers.status().is(500)).andReturn();
assertThat(result.getResponse().getErrorMessage()).isEqualTo("Cannot construct");
}