Add utility for safe pattern compiling

This commit is contained in:
ljacqu
2016-06-24 23:50:11 +02:00
parent 54ababdd28
commit 6812cfa4db
4 changed files with 106 additions and 8 deletions
@@ -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.
*