Skip to content

Commit dd56cd8

Browse files
committed
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.
1 parent a02159e commit dd56cd8

File tree

3 files changed

+696
-0
lines changed

3 files changed

+696
-0
lines changed

src/main/java/com/gitblit/servlet/RawServlet.java

+9
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ public static String asLink(String baseURL, String repository, String branch, St
9999
if (baseURL.length() > 0 && baseURL.charAt(baseURL.length() - 1) == '/') {
100100
baseURL = baseURL.substring(0, baseURL.length() - 1);
101101
}
102+
if (repository.length() > 0 && repository.charAt(repository.length() - 1) == '/') {
103+
repository = repository.substring(0, repository.length() - 1);
104+
}
105+
if (repository.length() > 0 && repository.charAt(0) == '/') {
106+
repository = repository.substring(1);
107+
}
102108

103109
char fsc = '!';
104110
char c = GitblitContext.getManager(IRuntimeManager.class).getSettings().getChar(Keys.web.forwardSlashCharacter, '/');
@@ -109,6 +115,9 @@ public static String asLink(String baseURL, String repository, String branch, St
109115
branch = Repository.shortenRefName(branch).replace('/', fsc);
110116
}
111117

118+
if (path != null && path.length() > 0 && path.charAt(0) == '/') {
119+
path = path.substring(1);
120+
}
112121
String encodedPath = path == null ? "" : path.replace('/', fsc);
113122
return baseURL + Constants.RAW_PATH + repository + "/" + (branch == null ? "" : (branch + "/" + encodedPath));
114123
}

0 commit comments

Comments
 (0)