From 661aca847523964324a29b4fc191fb8b00a8bed4 Mon Sep 17 00:00:00 2001 From: Jacob Buckheit Date: Wed, 14 Oct 2020 21:35:20 -0400 Subject: [PATCH] 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 --- .../ChatNotificationsPlugin.java | 4 ++-- .../ChatNotificationsPluginTest.java | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatnotifications/ChatNotificationsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatnotifications/ChatNotificationsPlugin.java index a412756fa1..44069b177d 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatnotifications/ChatNotificationsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatnotifications/ChatNotificationsPlugin.java @@ -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 \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); } } diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/chatnotifications/ChatNotificationsPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/chatnotifications/ChatNotificationsPluginTest.java index 7fc7f2aad6..b341d62de6 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/chatnotifications/ChatNotificationsPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/chatnotifications/ChatNotificationsPluginTest.java @@ -113,6 +113,25 @@ public class ChatNotificationsPluginTest verify(messageNode).setValue("test test 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(".Your divine potion effect is about to expire."); + } + @Test public void testFullStop() {