]> source.dussan.org Git - gitblit.git/commitdiff
Improve pages servlet raw navigation (issue-411)
authorJames Moger <james.moger@gitblit.com>
Wed, 23 Apr 2014 16:06:59 +0000 (12:06 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 23 Apr 2014 16:06:59 +0000 (12:06 -0400)
src/main/java/com/gitblit/servlet/PagesServlet.java

index 5124b8caab03c4524525d0b571eeba8722cba1d3..f4e8bb234762e5ad6803fe16e20c57bc880bf3fa 100644 (file)
@@ -111,6 +111,10 @@ public class PagesServlet extends DaggerServlet {
                        // strip leading /\r
                        path = path.substring(1);\r
                }\r
+               if (path.charAt(path.length() - 1) == '/') {\r
+                       // strip trailing slash\r
+                       path = path.substring(0, path.length() - 1);\r
+               }\r
 \r
                // determine repository and resource from url\r
                String repository = "";\r
@@ -229,7 +233,7 @@ public class PagesServlet extends DaggerServlet {
                                        response.getWriter().append("<thead><tr><th>path</th><th>mode</th><th>size</th></tr>");\r
                                        response.getWriter().append("</thead>");\r
                                        response.getWriter().append("<tbody>");\r
-                                       String pattern = "<tr><td><a href=\"{0}\">{1}</a></td><td>{2}</td><td>{3}</td></tr>";\r
+                                       String pattern = "<tr><td><a href=\"{0}/{1}\">{1}</a></td><td>{2}</td><td>{3}</td></tr>";\r
                                        final ByteFormat byteFormat = new ByteFormat();\r
                                        List<PathModel> entries = JGitUtils.getFilesInPath(r, resource, commit);\r
                                        if (!entries.isEmpty()) {\r
@@ -238,8 +242,15 @@ public class PagesServlet extends DaggerServlet {
                                                        entries.add(0, new PathModel("..", resource + "/..", 0, FileMode.TREE.getBits(), null, null));\r
                                                }\r
                                        }\r
+\r
+                                       String basePath = request.getServletPath() + request.getPathInfo();\r
+                                       if (basePath.charAt(basePath.length() - 1) == '/') {\r
+                                               // strip trailing slash\r
+                                               basePath = basePath.substring(0, basePath.length() - 1);\r
+                                       }\r
                                        for (PathModel entry : entries) {\r
-                                               response.getWriter().append(MessageFormat.format(pattern, entry.path, entry.name, JGitUtils.getPermissionsFromMode(entry.mode), byteFormat.format(entry.size)));\r
+                                               response.getWriter().append(MessageFormat.format(pattern, basePath, entry.name,\r
+                                                               JGitUtils.getPermissionsFromMode(entry.mode), byteFormat.format(entry.size)));\r
                                        }\r
                                        response.getWriter().append("</tbody>");\r
                                        response.getWriter().append("</table>");\r