]> source.dussan.org Git - gitblit.git/commitdiff
Match longest repository path towards the shortest pr-950
authorpaladox <paladox@users.noreply.github.com>
Mon, 23 Nov 2015 17:58:38 +0000 (17:58 +0000)
committerJames Moger <james.moger@gitblit.com>
Mon, 23 Nov 2015 18:32:00 +0000 (13:32 -0500)
This was originally from https://github.com/gitblit/gitblit/pull/950 but seems to have been reverted when develop branch was merged with master.

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

index 1d2724bca7054a6b26fd5948f63f9d6cf598bc61..e11bc505aeabf236d0f3a54107b57fef3d73f63f 100644 (file)
@@ -166,23 +166,14 @@ public class RawServlet extends HttpServlet {
                }
 
                // determine repository and resource from url
-               String repository = "";
+               String repository = path;
                Repository r = null;
-               int offset = 0;
-               while (r == null) {
-                       int slash = path.indexOf('/', offset);
-                       if (slash == -1) {
-                               repository = path;
-                       } else {
-                               repository = path.substring(0, slash);
-                       }
-                       offset = ( slash + 1 );
+               int terminator = repository.length();
+               do {
+                       repository = repository.substring(0, terminator);
                        r = repositoryManager.getRepository(repository, false);
-                       if (repository.equals(path)) {
-                               // either only repository in url or no repository found
-                               break;
-                       }
-               }
+                       terminator = repository.lastIndexOf('/');
+               } while (r == null && terminator > -1 );
 
                ServletContext context = request.getSession().getServletContext();