From: Joel Johnson Date: Wed, 9 Dec 2015 22:58:33 +0000 (-0700) Subject: revise logic for forcing dotfile to text X-Git-Tag: v1.8.0~30^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F983%2Fhead;p=gitblit.git revise logic for forcing dotfile to text --- diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java index 81793bc7..897047d8 100644 --- a/src/main/java/com/gitblit/servlet/RawServlet.java +++ b/src/main/java/com/gitblit/servlet/RawServlet.java @@ -233,7 +233,14 @@ public class RawServlet extends HttpServlet { try { String ext = StringUtils.getFileExtension(file).toLowerCase(); - String contentType = file.charAt(0) == '.' ? "text/plain" : 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 exts = runtimeManager.getSettings().getStrings(Keys.web.prettyPrintExtensions);