From a502d96a860456ec5e8c96761db70f7cabb74751 Mon Sep 17 00:00:00 2001 From: Paul Martin <paul@paulsputer.com> Date: Sat, 30 Apr 2016 04:19:14 -0400 Subject: [PATCH] Merge pull request #1073 from gitblit/1062-DocEditorUpdates --- src/main/java/com/gitblit/servlet/RawServlet.java | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java index e11bc50..dca5773 100644 --- a/src/main/java/com/gitblit/servlet/RawServlet.java +++ b/src/main/java/com/gitblit/servlet/RawServlet.java @@ -233,7 +233,14 @@ try { String ext = StringUtils.getFileExtension(file).toLowerCase(); - String contentType = quickContentTypes.get(ext); + // We can't parse out an extension for classic "dotfiles", so make a general assumption that + // they're text files to allow presenting them in browser instead of only for download. + // + // However, that only holds for files with no other extension included, for files that happen + // to start with a dot but also include an extension, process the extension normally. + // This logic covers .gitattributes, .gitignore, .zshrc, etc., but does not cover .mongorc.js, .zshrc.bak + boolean isExtensionlessDotfile = file.charAt(0) == '.' && (file.length() == 1 || file.indexOf('.', 1) < 0); + String contentType = isExtensionlessDotfile ? "text/plain" : quickContentTypes.get(ext); if (contentType == null) { List<String> exts = runtimeManager.getSettings().getStrings(Keys.web.prettyPrintExtensions); @@ -357,7 +364,7 @@ if (pathEntries.get(0).path.indexOf('/') > -1) { // we are in a subdirectory, add parent directory link String pp = URLEncoder.encode(requestedPath, Constants.ENCODING); - pathEntries.add(0, new PathModel("..", pp + "/..", 0, FileMode.TREE.getBits(), null, null)); + pathEntries.add(0, new PathModel("..", pp + "/..", null, 0, FileMode.TREE.getBits(), null, null)); } } -- Gitblit v1.9.1