mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-18 11:11:07 +01:00
improve validation of repository name
This commit is contained in:
@@ -52,10 +52,12 @@ public class ValidationUtil
|
|||||||
private static final String REGEX_NAME = "^[A-z0-9\\.\\-_]+$";
|
private static final String REGEX_NAME = "^[A-z0-9\\.\\-_]+$";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static final String REGEX_REPOSITORYNAME = "^[A-z0-9\\.\\-_/]+$";
|
private static final String REGEX_REPOSITORYNAME =
|
||||||
|
"^[A-z0-9][A-z0-9\\.\\-_/]*$";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static final String REGEX_USERNAME = "^[A-z0-9\\.\\-_@]|[^ ]([A-z0-9\\.\\-_@ ]*[A-z0-9\\.\\-_@]|[^ ])?$";
|
private static final String REGEX_USERNAME =
|
||||||
|
"^[A-z0-9\\.\\-_@]|[^ ]([A-z0-9\\.\\-_@ ]*[A-z0-9\\.\\-_@]|[^ ])?$";
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
@@ -139,7 +141,8 @@ public class ValidationUtil
|
|||||||
*/
|
*/
|
||||||
public static boolean isRepositoryNameValid(String name)
|
public static boolean isRepositoryNameValid(String name)
|
||||||
{
|
{
|
||||||
return Util.isNotEmpty(name) && name.matches(REGEX_REPOSITORYNAME);
|
return Util.isNotEmpty(name) && name.matches(REGEX_REPOSITORYNAME)
|
||||||
|
&&!name.contains("..") &&!name.endsWith("/.") &&!name.endsWith(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -130,6 +130,24 @@ public class ValidationUtilTest
|
|||||||
assertFalse(ValidationUtil.isNotContaining("test", "t"));
|
assertFalse(ValidationUtil.isNotContaining("test", "t"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testIsRepositoryNameValid()
|
||||||
|
{
|
||||||
|
assertTrue(ValidationUtil.isRepositoryNameValid("scm"));
|
||||||
|
assertTrue(ValidationUtil.isRepositoryNameValid("scm/main"));
|
||||||
|
assertTrue(ValidationUtil.isRepositoryNameValid("scm/plugins/git-plugin"));
|
||||||
|
|
||||||
|
// issue 142
|
||||||
|
assertFalse(ValidationUtil.isRepositoryNameValid("."));
|
||||||
|
assertFalse(ValidationUtil.isRepositoryNameValid(".scm/plugins"));
|
||||||
|
assertTrue(ValidationUtil.isRepositoryNameValid("scm/plugins/."));
|
||||||
|
assertFalse(ValidationUtil.isRepositoryNameValid("scm/../plugins"));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user