From dd56cd85715d0b8f6d9dfaca468f9589868cbded Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Wed, 4 Nov 2020 20:35:31 +0100 Subject: raw: Strip leading and trailing slash from repo and path names for link When creating a link for raw display, a trailing slash is stripped from the end of the base URL. Also do this for the repository, as well as stripping leading slashes from the repository and the path values. --- src/main/java/com/gitblit/servlet/RawServlet.java | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/main') diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java index dca57730..5fba78b5 100644 --- a/src/main/java/com/gitblit/servlet/RawServlet.java +++ b/src/main/java/com/gitblit/servlet/RawServlet.java @@ -99,6 +99,12 @@ public class RawServlet extends HttpServlet { if (baseURL.length() > 0 && baseURL.charAt(baseURL.length() - 1) == '/') { baseURL = baseURL.substring(0, baseURL.length() - 1); } + if (repository.length() > 0 && repository.charAt(repository.length() - 1) == '/') { + repository = repository.substring(0, repository.length() - 1); + } + if (repository.length() > 0 && repository.charAt(0) == '/') { + repository = repository.substring(1); + } char fsc = '!'; char c = GitblitContext.getManager(IRuntimeManager.class).getSettings().getChar(Keys.web.forwardSlashCharacter, '/'); @@ -109,6 +115,9 @@ public class RawServlet extends HttpServlet { branch = Repository.shortenRefName(branch).replace('/', fsc); } + if (path != null && path.length() > 0 && path.charAt(0) == '/') { + path = path.substring(1); + } String encodedPath = path == null ? "" : path.replace('/', fsc); return baseURL + Constants.RAW_PATH + repository + "/" + (branch == null ? "" : (branch + "/" + encodedPath)); } -- cgit v1.2.3