mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Accounting for trailing slashes and .git in project name.
This commit is contained in:
parent
a654529090
commit
8483e0b86a
2 changed files with 20 additions and 1 deletions
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue