Skip to content

Commit afc9dee

Browse files
committed
Merge pull request gitblit-org#983 from mrjoel/mrjoel-dotfiledetection
revise logic for forcing dotfile to text
2 parents f7e28a4 + 68100a2 commit afc9dee

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,14 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
233233
try {
234234

235235
String ext = StringUtils.getFileExtension(file).toLowerCase();
236-
String contentType = file.charAt(0) == '.' ? "text/plain" : quickContentTypes.get(ext);
236+
// We can't parse out an extension for classic "dotfiles", so make a general assumption that
237+
// they're text files to allow presenting them in browser instead of only for download.
238+
//
239+
// However, that only holds for files with no other extension included, for files that happen
240+
// to start with a dot but also include an extension, process the extension normally.
241+
// This logic covers .gitattributes, .gitignore, .zshrc, etc., but does not cover .mongorc.js, .zshrc.bak
242+
boolean isExtensionlessDotfile = file.charAt(0) == '.' && (file.length() == 1 || file.indexOf('.', 1) < 0);
243+
String contentType = isExtensionlessDotfile ? "text/plain" : quickContentTypes.get(ext);
237244

238245
if (contentType == null) {
239246
List<String> exts = runtimeManager.getSettings().getStrings(Keys.web.prettyPrintExtensions);

0 commit comments

Comments
 (0)