Skip to content

Commit b77d119

Browse files
authored
Merge pull request #18 from newclear/master
fix: not redirected for branch name with / in it.
2 parents bac4844 + 26ef7a0 commit b77d119

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/main/java/com/dkaedv/glghproxy/Application.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
public class Application extends SpringBootServletInitializer {
1414

1515
public static void main(String[] args) {
16+
System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
1617
SpringApplication.run(Application.class, args);
1718
}
1819

src/main/java/com/dkaedv/glghproxy/controller/RedirectsController.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import org.springframework.web.bind.annotation.PathVariable;
66
import org.springframework.web.bind.annotation.RequestMapping;
77

8+
import javax.servlet.http.HttpServletRequest;
9+
import org.springframework.web.servlet.HandlerMapping;
10+
import org.springframework.util.AntPathMatcher;
11+
812
@Controller
913
public class RedirectsController {
1014

@@ -38,13 +42,18 @@ public String commit(
3842
return "redirect:" + gitlabUrl + "/" + namespace + "/" + repo + "/commit/" + sha;
3943
}
4044

41-
@RequestMapping("/{namespace}/{repo}/tree/{branch}")
45+
@RequestMapping("/{namespace}/{repo}/tree/**")
4246
public String repoTree(
4347
@PathVariable String namespace,
4448
@PathVariable String repo,
45-
@PathVariable String branch
49+
HttpServletRequest request
50+
//@PathVariable String branch
4651
) {
47-
52+
String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
53+
String bestMatchPattern = (String ) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
54+
AntPathMatcher apm = new AntPathMatcher();
55+
String branch = apm.extractPathWithinPattern(bestMatchPattern, path);
56+
4857
return "redirect:" + gitlabUrl + "/" + namespace + "/" + repo + "/tree/" + branch;
4958
}
5059

0 commit comments

Comments
 (0)