Skip to content

Commit 09419e4

Browse files
author
Moises Trovo
committed
Fixed IndexOutOfBoundsException for paths ending in "/"
1 parent 2dbe941 commit 09419e4

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

handlebar/src/main/java/com/sampullara/mustache/Handlebar.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,17 @@ public static void main(String[] args) throws Exception {
8585
Handler handler = new AbstractHandler() {
8686
public void handle(String s, Request r, HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
8787
String pathInfo = req.getPathInfo();
88+
89+
if (pathInfo.endsWith("/")) pathInfo += "index.html";
90+
8891
String extension = pathInfo.substring(pathInfo.lastIndexOf(".") + 1);
8992
String base = pathInfo.substring(0, pathInfo.lastIndexOf("."));
9093
String mimeType = mimeTypes.get(extension);
9194
res.setContentType(mimeType == null ? "text/html" : mimeType);
9295
res.setCharacterEncoding("utf-8");
9396
if (mimeType == null || mimeType.equals("text/html")) {
9497
// Handle like a template
95-
String filename = pathInfo.endsWith("/") ? pathInfo + "index.html" : pathInfo.substring(1);
98+
String filename = pathInfo.substring(1);
9699
try {
97100
MustacheFactory mc = new DefaultMustacheFactory(new File("."));
98101
Mustache mustache = mc.compile(filename);

0 commit comments

Comments
 (0)