]> source.dussan.org Git - gitblit.git/commitdiff
revise logic for forcing dotfile to text 983/head
authorJoel Johnson <mrjoel@lixil.net>
Wed, 9 Dec 2015 22:58:33 +0000 (15:58 -0700)
committerJoel Johnson <mrjoel@lixil.net>
Wed, 9 Dec 2015 22:58:33 +0000 (15:58 -0700)
src/main/java/com/gitblit/servlet/RawServlet.java

index 81793bc77a6684d6255677e0d1b3f59f005e3e52..897047d86066c352b67831f92ec7a41b2a94a087 100644 (file)
@@ -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<String> exts = runtimeManager.getSettings().getStrings(Keys.web.prettyPrintExtensions);