summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorFlorian Zschocke <f.zschocke+git@gmail.com>2020-11-09 20:21:08 +0100
committerFlorian Zschocke <f.zschocke+git@gmail.com>2020-11-09 23:56:53 +0100
commit1570199d3fc21c26b1c2a6603b9dc24317176b3f (patch)
tree10f3028595f201d155892c13adb96748557c555a /src/main/java
parent26db31876aaf59651bb8b8a0b65bb4865f090788 (diff)
downloadgitblit-1570199d3fc21c26b1c2a6603b9dc24317176b3f.tar.gz
gitblit-1570199d3fc21c26b1c2a6603b9dc24317176b3f.zip
raw: Fix getPath with lead-ins or missing trailing slashes after the branch.
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/gitblit/servlet/RawServlet.java15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java
index 8213850a..90e8ac74 100644
--- a/src/main/java/com/gitblit/servlet/RawServlet.java
+++ b/src/main/java/com/gitblit/servlet/RawServlet.java
@@ -165,13 +165,26 @@ public class RawServlet extends HttpServlet {
{
if (pathInfo == null || pathInfo.isEmpty() || pathInfo.equals("/")) return "";
String base = repository + "/" + branch;
+
+ // 'repository/' or 'repository/branch' or 'repository/branch/'
if (pathInfo.equals(base)) {
return "";
}
- String path = pathInfo.substring(pathInfo.indexOf(base) + base.length() + 1);
+ // I have no idea why 'indexOf(base)' is used, which assumes something could come before 'base' in
+ // the pathInfo string. But since it is here, we handle it until we completly refactor the paths used
+ // in Gitblit to something sensible.
+ // 'leadin/repository/'
+ // 'leadin/repository/branch'
+ int pathStart = pathInfo.indexOf(base) + base.length();
+ // 'leadin/repository/branch/'
+ if (pathStart < pathInfo.length() && pathInfo.charAt(pathStart) == '/') pathStart++;
+ if (pathInfo.length() == pathStart) return "";
+ String path = pathInfo.substring(pathStart);
+ // 'leadin/repository/branch/path/'
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
+ // 'leadin/repository/branch/path'
char c = runtimeManager.getSettings().getChar(Keys.web.forwardSlashCharacter, '/');
return path.replace('!', '/').replace(c, '/');
}