Skip to content

Commit

Permalink
Trap regex error.
Browse files Browse the repository at this point in the history
  • Loading branch information
riverwanderer committed Sep 18, 2023
1 parent b8c3441 commit 7ccef13
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions vassal-app/src/main/java/VASSAL/configure/ConfigureTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7ccef13

Please sign in to comment.