From 906ac6511a9b1a77d954e4fdedc0d8e3dd26e6d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 29 Apr 2014 21:23:13 +0200 Subject: [PATCH] Add cleaning for reverse, underline, and italic formatting. --- .../net/pterodactylus/irc/util/MessageCleaner.java | 18 +++++++++++++++++- .../net/pterodactylus/irc/util/MessageCleanerTest.java | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/irc/util/MessageCleaner.java b/src/main/java/net/pterodactylus/irc/util/MessageCleaner.java index 6d0e3a2..9c5aab7 100644 --- a/src/main/java/net/pterodactylus/irc/util/MessageCleaner.java +++ b/src/main/java/net/pterodactylus/irc/util/MessageCleaner.java @@ -17,6 +17,10 @@ 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')) { diff --git a/src/test/java/net/pterodactylus/irc/util/MessageCleanerTest.java b/src/test/java/net/pterodactylus/irc/util/MessageCleanerTest.java index fd4b9b9..bd5a2a2 100644 --- a/src/test/java/net/pterodactylus/irc/util/MessageCleanerTest.java +++ b/src/test/java/net/pterodactylus/irc/util/MessageCleanerTest.java @@ -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")); + } + } -- 2.7.4