diff options
author | Florian Zschocke <f.zschocke+git@gmail.com> | 2020-11-04 20:35:31 +0100 |
---|---|---|
committer | Florian Zschocke <f.zschocke+git@gmail.com> | 2020-11-09 23:19:53 +0100 |
commit | dd56cd85715d0b8f6d9dfaca468f9589868cbded (patch) | |
tree | bf1ab9c35473b0fad99b33208e85772e4f2ce519 /src/main | |
parent | a02159e6378d63d0e1ad3c04a05462d9fc62fe89 (diff) | |
download | gitblit-dd56cd85715d0b8f6d9dfaca468f9589868cbded.tar.gz gitblit-dd56cd85715d0b8f6d9dfaca468f9589868cbded.zip |
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.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/gitblit/servlet/RawServlet.java | 9 |
1 files changed, 9 insertions, 0 deletions
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)); } |