chat notifier: fix matching messages with included punctuation
The punctuation is not in \b or \s, so additionally include \z. Also added \A for the beginning, which would have the same problem, which the test also tests for. Co-authored-by: Adam <Adam@sigterm.info>
This commit is contained in:
@@ -120,8 +120,8 @@ public class ChatNotificationsPlugin extends Plugin
|
||||
.map(this::quoteAndIgnoreColor) // regex escape and ignore nested colors in the target message
|
||||
.collect(Collectors.joining("|"));
|
||||
// To match <word> \b doesn't work due to <> not being in \w,
|
||||
// so match \b or \s
|
||||
highlightMatcher = Pattern.compile("(?:\\b|(?<=\\s))(" + joined + ")(?:\\b|(?=\\s))", Pattern.CASE_INSENSITIVE);
|
||||
// so match \b or \s, as well as \A and \z for beginning and end of input respectively
|
||||
highlightMatcher = Pattern.compile("(?:\\b|(?<=\\s)|\\A)(?:" + joined + ")(?:\\b|(?=\\s)|\\z)", Pattern.CASE_INSENSITIVE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,25 @@ public class ChatNotificationsPluginTest
|
||||
verify(messageNode).setValue("test <colHIGHLIGHT><lt>test<gt><colNORMAL> test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchEntireMessage()
|
||||
{
|
||||
when(config.highlightWordsString()).thenReturn(".Your divine potion effect is about to expire.");
|
||||
|
||||
String message = ".Your divine potion effect is about to expire.";
|
||||
MessageNode messageNode = mock(MessageNode.class);
|
||||
when(messageNode.getValue()).thenReturn(message);
|
||||
|
||||
ChatMessage chatMessage = new ChatMessage();
|
||||
chatMessage.setType(ChatMessageType.PUBLICCHAT);
|
||||
chatMessage.setMessageNode(messageNode);
|
||||
|
||||
chatNotificationsPlugin.startUp(); // load highlight config
|
||||
chatNotificationsPlugin.onChatMessage(chatMessage);
|
||||
|
||||
verify(messageNode).setValue("<colHIGHLIGHT>.Your divine potion effect is about to expire.<colNORMAL>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFullStop()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user