Add cleaning for reverse, underline, and italic formatting.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 29 Apr 2014 19:23:13 +0000 (21:23 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 29 Apr 2014 19:23:13 +0000 (21:23 +0200)
src/main/java/net/pterodactylus/irc/util/MessageCleaner.java
src/test/java/net/pterodactylus/irc/util/MessageCleanerTest.java

index 6d0e3a2..9c5aab7 100644 (file)
 
 package net.pterodactylus.irc.util;
 
+import static net.pterodactylus.irc.util.MessageCleaner.Attributes.italics;
+import static net.pterodactylus.irc.util.MessageCleaner.Attributes.reverse;
+import static net.pterodactylus.irc.util.MessageCleaner.Attributes.underline;
+
 import java.io.IOException;
 import java.io.StringReader;
 import java.util.EnumSet;
@@ -34,7 +38,10 @@ public class MessageCleaner {
 
                bold,
                color,
-               clear
+               clear,
+               reverse,
+               underline,
+               italics
 
        }
 
@@ -84,6 +91,15 @@ public class MessageCleaner {
                                if ((c == 15) && (attributes.contains(Attributes.clear))) {
                                        continue;
                                }
+                               if ((c == 22) && attributes.contains(reverse)) {
+                                       continue;
+                               }
+                               if ((c == 29) && attributes.contains(italics)) {
+                                       continue;
+                               }
+                               if ((c == 31) && attributes.contains(underline)) {
+                                       continue;
+                               }
                                if (inColorCode > 0) {
                                        if (inColorCode == 1) {
                                                if ((c < '0') || (c > '9')) {
index fd4b9b9..bd5a2a2 100644 (file)
@@ -91,4 +91,22 @@ public class MessageCleanerTest {
                assertThat(clean, is("This contains bold and color and clear characters."));
        }
 
+       @Test
+       public void removeUnderlineFormatting() {
+               MessageCleaner messageCleaner = MessageCleaner.getDefaultInstance();
+               assertThat(messageCleaner.clean("Text\u0016underline"), is("Textunderline"));
+       }
+
+       @Test
+       public void removeReverseFormatting() {
+               MessageCleaner messageCleaner = MessageCleaner.getDefaultInstance();
+               assertThat(messageCleaner.clean("Text\u001freverse"), is("Textreverse"));
+       }
+
+       @Test
+       public void removeItalicFormatting() {
+               MessageCleaner messageCleaner = MessageCleaner.getDefaultInstance();
+               assertThat(messageCleaner.clean("Text\u001ditalics"), is("Textitalics"));
+       }
+
 }