Added a basic input validation for shortUrl
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package tk.draganczuk.url;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Utils {
|
||||
private static final Random random = new Random(System.currentTimeMillis());
|
||||
|
||||
private static final String SHORT_URL_PATTERN = "[a-z0-9]+";
|
||||
private static final Pattern PATTERN = Pattern.compile(SHORT_URL_PATTERN);
|
||||
|
||||
public static String randomString() {
|
||||
int leftLimit = 48; // numeral '0'
|
||||
int rightLimit = 122; // letter 'z'
|
||||
@@ -18,4 +22,9 @@ public class Utils {
|
||||
StringBuilder::append)
|
||||
.toString();
|
||||
}
|
||||
|
||||
public static boolean validate(String shortUrl) {
|
||||
return PATTERN.matcher(shortUrl)
|
||||
.matches();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user