From 7ccef13ad51b5c6e194788bb00b620a16bfd9a56 Mon Sep 17 00:00:00 2001 From: riverwanderer <58135975+riverwanderer@users.noreply.github.com> Date: Mon, 18 Sep 2023 07:23:20 +0100 Subject: [PATCH] Trap regex error. --- .../java/VASSAL/configure/ConfigureTree.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/vassal-app/src/main/java/VASSAL/configure/ConfigureTree.java b/vassal-app/src/main/java/VASSAL/configure/ConfigureTree.java index c2bd235aca..ae1cec1c34 100644 --- a/vassal-app/src/main/java/VASSAL/configure/ConfigureTree.java +++ b/vassal-app/src/main/java/VASSAL/configure/ConfigureTree.java @@ -2662,15 +2662,17 @@ else if (c instanceof PrototypeDefinition) { */ private boolean checkString(String target, String searchString) { if (searchParameters.isMatchRegex()) { - // patch search string to avoid exception when Regex starts with * only - if (searchString.substring(0, 1).equals("*")) { - searchString = "." + searchString; - } - if (searchParameters.isMatchCase()) { - return target.matches(searchString); + try { + if (searchParameters.isMatchCase()) { + return target.matches(searchString); + } + else { + return target.toLowerCase().matches(searchString.toLowerCase()); + } } - else { - return target.toLowerCase().matches(searchString.toLowerCase()); + catch (java.util.regex.PatternSyntaxException e) { + logger.error("Search string is not a valid Regular Expression: " + e.getMessage()); //NON-NLS + return false; } } else {