]> source.dussan.org Git - gitblit.git/commitdiff
raw: Fix getPath with trailing slash that was escaped
authorFlorian Zschocke <f.zschocke+git@gmail.com>
Mon, 9 Nov 2020 19:27:31 +0000 (20:27 +0100)
committerFlorian Zschocke <f.zschocke+git@gmail.com>
Mon, 9 Nov 2020 23:02:53 +0000 (00:02 +0100)
While this may be an unlikely scenario, let's still prevent this.
When a link was created for a path that ends in a trailing slash,
that trailing slash would be replaced with the `forwardSlashCharacter`.
But in getPath that final slash would be transformed back *after* the
check to chop off trailing slashes. This is now switched so that such a
trailing slash is also chopped off.

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

index 90e8ac746379577f8b7d94e3eff7feb7f67891ee..b0cba7879cda201bd6ea5eb5e7ae66ddfae97b4d 100644 (file)
@@ -179,14 +179,18 @@ public class RawServlet extends HttpServlet {
                // 'leadin/repository/branch/'
                if (pathStart < pathInfo.length() && pathInfo.charAt(pathStart) == '/') pathStart++;
                if (pathInfo.length() == pathStart) return "";
+               // 'leadin/repository/branch/path'
                String path = pathInfo.substring(pathStart);
+
+               char c = runtimeManager.getSettings().getChar(Keys.web.forwardSlashCharacter, '/');
+               path =  path.replace('!', '/').replace(c, '/');
+
+               // 'repository/branch/path/'
                // 'leadin/repository/branch/path/'
                if (path.endsWith("/")) {
                        path = path.substring(0, path.length() - 1);
                }
-               // 'leadin/repository/branch/path'
-               char c = runtimeManager.getSettings().getChar(Keys.web.forwardSlashCharacter, '/');
-               return path.replace('!', '/').replace(c, '/');
+               return path;
        }
 
        protected boolean renderIndex() {