summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorFlorian Zschocke <f.zschocke+git@gmail.com>2020-11-09 23:08:22 +0100
committerFlorian Zschocke <f.zschocke+git@gmail.com>2020-11-10 00:05:07 +0100
commit6876537c856dda897f081430bb11b394f8b291bb (patch)
treeb587da62023fcde2e6d905ea019a38f9f9fafd1e /src/main
parent3212dc014c445425cc09f8d92065f1afb4e53065 (diff)
downloadgitblit-6876537c856dda897f081430bb11b394f8b291bb.tar.gz
gitblit-6876537c856dda897f081430bb11b394f8b291bb.zip
raw: Fix raw links to branches with a slash in their name
When a branch has a slash in the name, the raw servlet was not able to find the path under that branch. This is due to the replacement of the forward slash character for URLs. It was not taken into account when comparing the branch name later. This fixes #1290 and its duplicates #1234 and #813.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/gitblit/servlet/RawServlet.java17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java
index b0cba787..9161eb6a 100644
--- a/src/main/java/com/gitblit/servlet/RawServlet.java
+++ b/src/main/java/com/gitblit/servlet/RawServlet.java
@@ -69,6 +69,9 @@ import com.google.inject.Singleton;
@Singleton
public class RawServlet extends HttpServlet {
+ // Forward slash character
+ static final char FSC = '!';
+
private static final long serialVersionUID = 1L;
private transient Logger logger = LoggerFactory.getLogger(RawServlet.class);
@@ -106,10 +109,9 @@ public class RawServlet extends HttpServlet {
repository = repository.substring(1);
}
- char fsc = '!';
- char c = GitblitContext.getManager(IRuntimeManager.class).getSettings().getChar(Keys.web.forwardSlashCharacter, '/');
- if (c != '/') {
- fsc = c;
+ char fsc = GitblitContext.getManager(IRuntimeManager.class).getSettings().getChar(Keys.web.forwardSlashCharacter, '/');
+ if (fsc == '/') {
+ fsc = FSC;
}
if (branch != null) {
branch = Repository.shortenRefName(branch).replace('/', fsc);
@@ -164,7 +166,11 @@ public class RawServlet extends HttpServlet {
String getPath(String repository, String branch, String pathInfo)
{
if (pathInfo == null || pathInfo.isEmpty() || pathInfo.equals("/")) return "";
- String base = repository + "/" + branch;
+
+ // Make the branch look like in the URL, or else it won't match later in the `indexOf`.
+ char c = runtimeManager.getSettings().getChar(Keys.web.forwardSlashCharacter, '/');
+ char fsc = (c == '/') ? FSC : c;
+ String base = repository + "/" + Repository.shortenRefName(branch).replace('/', fsc);
// 'repository/' or 'repository/branch' or 'repository/branch/'
if (pathInfo.equals(base)) {
@@ -182,7 +188,6 @@ public class RawServlet extends HttpServlet {
// 'leadin/repository/branch/path'
String path = pathInfo.substring(pathStart);
- char c = runtimeManager.getSettings().getChar(Keys.web.forwardSlashCharacter, '/');
path = path.replace('!', '/').replace(c, '/');
// 'repository/branch/path/'