mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15:44 +01:00
merge with issue-69
This commit is contained in:
@@ -43,6 +43,10 @@ import sonia.scm.config.ScmConfiguration;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -58,6 +62,9 @@ public class HttpUtil
|
||||
/** authentication realm for basic authentication */
|
||||
public static final String AUTHENTICATION_REALM = "SONIA :: SCM Manager";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENCODING = "UTF-8";
|
||||
|
||||
/** authentication header */
|
||||
public static final String HEADER_WWW_AUTHENTICATE = "WWW-Authenticate";
|
||||
|
||||
@@ -112,6 +119,52 @@ public class HttpUtil
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param value
|
||||
*
|
||||
* @return
|
||||
* @since 1.9
|
||||
*/
|
||||
public static String decode(String value)
|
||||
{
|
||||
try
|
||||
{
|
||||
value = URLDecoder.decode(value, ENCODING);
|
||||
}
|
||||
catch (UnsupportedEncodingException ex)
|
||||
{
|
||||
throw new RuntimeException("could not decode", ex);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param value
|
||||
*
|
||||
* @return
|
||||
* @since 1.9
|
||||
*/
|
||||
public static String encode(String value)
|
||||
{
|
||||
try
|
||||
{
|
||||
value = URLEncoder.encode(value, ENCODING);
|
||||
}
|
||||
catch (UnsupportedEncodingException ex)
|
||||
{
|
||||
throw new RuntimeException("could not encode", ex);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an unauthorized header back to the client
|
||||
*
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ValidationUtil
|
||||
private static final String REGEX_NAME = "^[A-z0-9\\.\\-_]+$";
|
||||
|
||||
/** Field description */
|
||||
private static final String REGEX_USERNAME = "^[A-z0-9\\.\\-_@]+$";
|
||||
private static final String REGEX_USERNAME = "^[^ ][A-z0-9\\.\\-_@ ]+[^ ]$";
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
|
||||
@@ -145,9 +145,12 @@ public class ValidationUtilTest
|
||||
assertTrue(ValidationUtil.isUsernameValid("Test123-git"));
|
||||
assertTrue(ValidationUtil.isUsernameValid("Test_user-123.git"));
|
||||
assertTrue(ValidationUtil.isUsernameValid("test@scm-manager.de"));
|
||||
assertTrue(ValidationUtil.isUsernameValid("test 123"));
|
||||
|
||||
// false
|
||||
assertFalse(ValidationUtil.isUsernameValid("test 123"));
|
||||
assertFalse(ValidationUtil.isUsernameValid(" test 123"));
|
||||
assertFalse(ValidationUtil.isUsernameValid(" test 123 "));
|
||||
assertFalse(ValidationUtil.isUsernameValid("test 123 "));
|
||||
assertFalse(ValidationUtil.isUsernameValid("test/123"));
|
||||
assertFalse(ValidationUtil.isUsernameValid("test%123"));
|
||||
assertFalse(ValidationUtil.isUsernameValid("test:123"));
|
||||
|
||||
Reference in New Issue
Block a user