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 e2e2699f2a..16127de3b6 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 @@ -117,9 +117,12 @@ public class ChatNotificationsPlugin extends Plugin { List items = Text.fromCSV(config.highlightWordsString()); String joined = items.stream() + .map(Text::escapeJagex) // we compare these strings to the raw Jagex ones .map(Pattern::quote) .collect(Collectors.joining("|")); - highlightMatcher = Pattern.compile("\\b(" + joined + ")\\b", Pattern.CASE_INSENSITIVE); + // 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); } } @@ -127,7 +130,6 @@ public class ChatNotificationsPlugin extends Plugin public void onChatMessage(ChatMessage chatMessage) { MessageNode messageNode = chatMessage.getMessageNode(); - String nodeValue = Text.removeTags(messageNode.getValue()); boolean update = false; switch (chatMessage.getType()) @@ -177,6 +179,7 @@ public class ChatNotificationsPlugin extends Plugin if (highlightMatcher != null) { + String nodeValue = messageNode.getValue(); Matcher matcher = highlightMatcher.matcher(nodeValue); boolean found = false; StringBuffer stringBuffer = new StringBuffer(); 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 6c154eaa9b..ffa54ccbae 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 @@ -93,6 +93,44 @@ public class ChatNotificationsPluginTest verify(messageNode).setValue("Deathbeam, Deathbeam OSRS"); } + @Test + public void testLtGt() + { + when(config.highlightWordsString()).thenReturn(""); + + String message = "test test test"; + 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("test test test"); + } + + @Test + public void testFullStop() + { + when(config.highlightWordsString()).thenReturn("test"); + + String message = "foo test. bar"; + 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("foo test. bar"); + } + @Test public void highlightListTest() {