From 36b5ce2fece6954ea5e8474b3e3a35dd4d338ac5 Mon Sep 17 00:00:00 2001
From: Michael Legart <michael@legart.dk>
Date: Thu, 04 Sep 2014 06:32:41 -0400
Subject: [PATCH] Pretty print perl modules
---
src/main/java/com/gitblit/servlet/RawServlet.java | 33 +++++++++++++++++++++++++++------
1 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java
index cde7b2e..a9e5820 100644
--- a/src/main/java/com/gitblit/servlet/RawServlet.java
+++ b/src/main/java/com/gitblit/servlet/RawServlet.java
@@ -94,11 +94,18 @@
if (baseURL.length() > 0 && baseURL.charAt(baseURL.length() - 1) == '/') {
baseURL = baseURL.substring(0, baseURL.length() - 1);
}
- String encodedPath = path.replace(' ', '-');
- try {
- encodedPath = URLEncoder.encode(encodedPath, "UTF-8");
- } catch (UnsupportedEncodingException e) {
+
+ char fsc = '!';
+ char c = GitblitContext.getManager(IRuntimeManager.class).getSettings().getChar(Keys.web.forwardSlashCharacter, '/');
+ if (c != '/') {
+ fsc = c;
}
+ if (branch != null) {
+ branch = branch.replace('/', fsc);
+ }
+
+ String encodedPath = path == null ? "" : path.replace(' ', '-');
+ encodedPath = encodedPath.replace('/', fsc);
return baseURL + Constants.RAW_PATH + repository + "/" + (branch == null ? "" : (branch + "/" + (path == null ? "" : encodedPath)));
}
@@ -109,7 +116,8 @@
if (fs > -1) {
branch = branch.substring(0, fs);
}
- return branch;
+ char c = runtimeManager.getSettings().getChar(Keys.web.forwardSlashCharacter, '/');
+ return branch.replace('!', '/').replace(c, '/');
}
protected String getPath(String repository, String branch, HttpServletRequest request) {
@@ -122,7 +130,8 @@
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
- return path;
+ char c = runtimeManager.getSettings().getChar(Keys.web.forwardSlashCharacter, '/');
+ return path.replace('!', '/').replace(c, '/');
}
protected boolean renderIndex() {
@@ -164,6 +173,9 @@
repository = path.substring(0, slash);
}
offset += slash;
+ if (offset == 0) {
+ offset++;
+ }
r = repositoryManager.getRepository(repository, false);
if (repository.equals(path)) {
// either only repository in url or no repository found
@@ -243,6 +255,15 @@
// load, interpret, and serve text content as UTF-8
String [] encodings = runtimeManager.getSettings().getStrings(Keys.web.blobEncodings).toArray(new String[0]);
String content = JGitUtils.getStringContent(r, commit.getTree(), requestedPath, encodings);
+ if (content == null) {
+ logger.error("RawServlet Failed to load {} {} {}", repository, commit.getName(), path);
+ String str = MessageFormat.format(
+ "# Error\nSorry, the requested resource **{0}** was not found.",
+ requestedPath);
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ error(response, str);
+ return;
+ }
byte [] bytes = content.getBytes(Constants.ENCODING);
response.setContentLength(bytes.length);
--
Gitblit v1.9.1