Check for escaped labels in binary file paths as well

See gh-264
This commit is contained in:
Dave Syer
2015-11-12 16:51:11 +00:00
parent c72e3857cd
commit eb97893b4c
2 changed files with 12 additions and 0 deletions

View File

@@ -87,6 +87,11 @@ public class ResourceController {
@PathVariable String profile, @PathVariable String label,
@PathVariable String path) throws IOException {
StandardEnvironment environment = new StandardEnvironment();
if (label != null && label.contains("(_)")) {
// "(_)" is uncommon in a git branch name, but "/" cannot be matched
// by Spring MVC
label = label.replace("(_)", "/");
}
environment.getPropertySources().addAfter(
StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME,
new EnvironmentPropertySource(

View File

@@ -85,4 +85,11 @@ public class ResourceControllerTests {
assertEquals("foo: dev_bar/spam", resource);
}
@Test
public void labelWithSlashForBinary() throws Exception {
this.environmentRepository.setSearchLocations("classpath:/test");
byte[] resource = this.controller.binary("foo", "bar", "dev(_)spam", "foo.txt");
assertEquals("foo: dev_bar/spam", new String(resource));
}
}