mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
Validate namespaces correctly
This commit is contained in:
@@ -27,17 +27,25 @@ package sonia.scm.repository;
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.util.ValidationUtil;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static sonia.scm.ScmConstraintViolationException.Builder.doThrow;
|
||||
|
||||
@Extension
|
||||
public class CustomNamespaceStrategy implements NamespaceStrategy {
|
||||
|
||||
private static final Pattern ONE_TO_THREE_DIGITS = Pattern.compile("[0-9]{1,3}");
|
||||
|
||||
@Override
|
||||
public String createNamespace(Repository repository) {
|
||||
String namespace = repository.getNamespace();
|
||||
|
||||
doThrow()
|
||||
.violation("invalid namespace", "namespace")
|
||||
.when(!ValidationUtil.isRepositoryNameValid(namespace) || namespace.matches("[0-9]{1,3}"));
|
||||
.when(
|
||||
!ValidationUtil.isRepositoryNameValid(namespace)
|
||||
|| ONE_TO_THREE_DIGITS.matcher(namespace).matches()
|
||||
|| namespace.equals("create"));
|
||||
|
||||
return namespace;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user