Skip to content

Commit

Permalink
Add repository name restriction.
Browse files Browse the repository at this point in the history
Only a-zA-Z0-9- are allowed.
  • Loading branch information
Andreas committed Jun 8, 2017
1 parent f9abf72 commit 793896f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;

import com.google.common.base.Predicate;
import com.google.common.base.Strings;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.io.Files;
Expand All @@ -20,6 +21,12 @@ public static String cleanFilename(String filename) {
return filename.replaceAll("[^a-zA-Z0-9\\@\\!\\#\\%\\&\\(\\)\\_\\-\\=\\+\\[\\]\\{\\}\\,\\;\\.äÄöÖüÜ ]+", "_");
}

public static boolean isValidRepositoryName(String name) {
boolean empty = Strings.isNullOrEmpty(name);
boolean validChars = Strings.nullToEmpty(name).matches("[a-zA-Z0-9-]+");
return !empty && validChars;
}

public static String relativize(File rootDir, File file) {
return relativize(rootDir.getAbsolutePath(), file.getAbsolutePath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ public static GitRepository open(File gitDir) throws IOException {
public static void create(File gitDir, String name, String description, GitAuthor author)
throws IOException, GitCommandException {

name = name.trim();
if (name.contains(" ")) {
throw new GitCommandException("No spaces are allowed in repository name!");
if (!FileUtils.isValidRepositoryName(name)) {
throw new GitCommandException(String.format("Repository name '%s' is not allowed. Only a-zA-Z0-9- are allowed.", name));
}

File repositoryDir = Paths.get(gitDir.getAbsolutePath(), name + ".git")
Expand Down

0 comments on commit 793896f

Please sign in to comment.