Add utility for safe pattern compiling
This commit is contained in:
@@ -15,6 +15,7 @@ import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import fr.xephi.authme.util.ValidationService;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -56,13 +57,7 @@ class OnJoinVerifier implements Reloadable {
|
||||
@Override
|
||||
public void reload() {
|
||||
String nickRegEx = settings.getProperty(RestrictionSettings.ALLOWED_NICKNAME_CHARACTERS);
|
||||
try {
|
||||
nicknamePattern = Pattern.compile(nickRegEx);
|
||||
} catch (Exception e) {
|
||||
nicknamePattern = Pattern.compile(".*?");
|
||||
ConsoleLogger.showError("Nickname pattern is not a valid regular expression! "
|
||||
+ "Fallback to allowing all nicknames");
|
||||
}
|
||||
nicknamePattern = Utils.safePatternCompile(nickRegEx);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Utility class for various operations used in the codebase.
|
||||
@@ -79,6 +80,15 @@ public final class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Pattern safePatternCompile(String pattern) {
|
||||
try {
|
||||
return Pattern.compile(pattern);
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.showError("Failed to compile pattern '" + pattern + "' - defaulting to allowing everything");
|
||||
return Pattern.compile(".*?");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the IP of the given player.
|
||||
*
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ValidationService implements Reloadable {
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
passwordRegex = Pattern.compile(settings.getProperty(RestrictionSettings.ALLOWED_PASSWORD_REGEX));
|
||||
passwordRegex = Utils.safePatternCompile(settings.getProperty(RestrictionSettings.ALLOWED_PASSWORD_REGEX));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user