Просмотр исходного кода

Accounting for trailing slashes and .git in project name.

Winston Li 12 лет назад
Родитель
Сommit
8483e0b86a

+ 2 - 1
services/git-bridge/src/uk/ac/ic/wlgitbridge/git/handler/WLRepositoryResolver.java

@@ -8,6 +8,7 @@ import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
 import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
 import uk.ac.ic.wlgitbridge.bridge.RepositorySource;
 import uk.ac.ic.wlgitbridge.git.exception.InvalidRootDirectoryPathException;
+import uk.ac.ic.wlgitbridge.util.Util;
 import uk.ac.ic.wlgitbridge.writelatex.SnapshotRepositoryBuilder;
 
 import javax.servlet.http.HttpServletRequest;
@@ -29,7 +30,7 @@ public class WLRepositoryResolver implements RepositoryResolver<HttpServletReque
     @Override
     public Repository open(HttpServletRequest httpServletRequest, String name) throws RepositoryNotFoundException, ServiceNotAuthorizedException, ServiceNotEnabledException, ServiceMayNotContinueException {
         try {
-            return repositorySource.getRepositoryWithNameAtRootDirectory(name, rootGitDirectory);
+            return repositorySource.getRepositoryWithNameAtRootDirectory(Util.removeAllSuffixes(name, "/", ".git"), rootGitDirectory);
         } catch (RepositoryNotFoundException e) {
             throw e;
         } catch (ServiceNotEnabledException e) {

+ 18 - 0
services/git-bridge/src/uk/ac/ic/wlgitbridge/util/Util.java

@@ -25,4 +25,22 @@ public class Util {
         return i != 0;
     }
 
+    private static String removeAllSuffix(String str, String suffix) {
+        int lastIndexOfSuffix;
+        String result = str;
+        while ((lastIndexOfSuffix = result.lastIndexOf(suffix)) > -1) {
+            result = result.substring(0, lastIndexOfSuffix);
+        }
+        return result;
+    }
+
+    /* removeAllSuffixes("something.git///", "/", ".git") => "something" */
+    public static String removeAllSuffixes(String str, String... suffixes) {
+        String result = str;
+        for (String suffix : suffixes) {
+            result = removeAllSuffix(result, suffix);
+        }
+        return result;
+    }
+
 }