diff options
Diffstat (limited to 'java/com/google')
3 files changed, 17 insertions, 8 deletions
diff --git a/java/com/google/gerrit/common/ProjectUtil.java b/java/com/google/gerrit/common/ProjectUtil.java index bfd5ef9294..e9d37818b9 100644 --- a/java/com/google/gerrit/common/ProjectUtil.java +++ b/java/com/google/gerrit/common/ProjectUtil.java @@ -15,15 +15,26 @@ package com.google.gerrit.common; public class ProjectUtil { + public static String sanitizeProjectName(String name) { + name = stripGitSuffix(name); + name = stripTrailingSlash(name); + return name; + } + public static String stripGitSuffix(String name) { if (name.endsWith(".git")) { // Be nice and drop the trailing ".git" suffix, which we never keep // in our database, but clients might mistakenly provide anyway. // name = name.substring(0, name.length() - 4); - while (name.endsWith("/")) { - name = name.substring(0, name.length() - 1); - } + name = stripTrailingSlash(name); + } + return name; + } + + private static String stripTrailingSlash(String name) { + while (name.endsWith("/")) { + name = name.substring(0, name.length() - 1); } return name; } diff --git a/java/com/google/gerrit/server/restapi/project/CreateProject.java b/java/com/google/gerrit/server/restapi/project/CreateProject.java index 56203702c3..b92fba8fe4 100644 --- a/java/com/google/gerrit/server/restapi/project/CreateProject.java +++ b/java/com/google/gerrit/server/restapi/project/CreateProject.java @@ -168,7 +168,7 @@ public class CreateProject } CreateProjectArgs args = new CreateProjectArgs(); - args.setProjectName(ProjectUtil.stripGitSuffix(name)); + args.setProjectName(ProjectUtil.sanitizeProjectName(name)); String parentName = MoreObjects.firstNonNull(Strings.emptyToNull(input.parent), allProjects.get()); diff --git a/java/com/google/gerrit/server/restapi/project/ProjectsCollection.java b/java/com/google/gerrit/server/restapi/project/ProjectsCollection.java index 6abf102d65..ed317aadc9 100644 --- a/java/com/google/gerrit/server/restapi/project/ProjectsCollection.java +++ b/java/com/google/gerrit/server/restapi/project/ProjectsCollection.java @@ -17,6 +17,7 @@ package com.google.gerrit.server.restapi.project; import com.google.common.collect.ListMultimap; import com.google.common.flogger.FluentLogger; import com.google.gerrit.common.Nullable; +import com.google.gerrit.common.ProjectUtil; import com.google.gerrit.extensions.registration.DynamicMap; import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.BadRequestException; @@ -42,7 +43,6 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; import java.io.IOException; -import org.eclipse.jgit.lib.Constants; @Singleton public class ProjectsCollection @@ -136,9 +136,7 @@ public class ProjectsCollection @Nullable private ProjectResource _parse(String id, boolean checkAccess) throws IOException, PermissionBackendException, ResourceConflictException { - if (id.endsWith(Constants.DOT_GIT_EXT)) { - id = id.substring(0, id.length() - Constants.DOT_GIT_EXT.length()); - } + id = ProjectUtil.sanitizeProjectName(id); Project.NameKey nameKey = new Project.NameKey(id); ProjectState state = projectCache.checkedGet(nameKey); |