diff options
5 files changed, 38 insertions, 31 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/irc/FormattedTextBuilder.java b/src/net/java/sip/communicator/impl/protocol/irc/FormattedTextBuilder.java index ed36cb0..18d7507 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/FormattedTextBuilder.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/FormattedTextBuilder.java @@ -28,6 +28,9 @@ public class FormattedTextBuilder /** * Append a string of text. * + * Make sure that the text is safe for your purposes, as it is appended + * without further modifications. + * * @param text string of text */ public void append(final String text) @@ -38,6 +41,9 @@ public class FormattedTextBuilder /** * Append a character. * + * Make sure that the character is safe for your purposes, as it is appended + * without further modifications. + * * @param c character */ public void append(final char c) diff --git a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java index fa1446f..2837945 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java @@ -1259,7 +1259,8 @@ public class IrcStack public void onUserPrivMessage(final UserPrivMsg msg) { final String user = msg.getSource().getNick(); - final String text = Utils.formatMessage(Utils.parseIrcMessage(msg.getText())); + final String text = + Utils.styleAsMessage(Utils.parseIrcMessage(msg.getText())); final MessageIrcImpl message = new MessageIrcImpl(text, OperationSetBasicInstantMessaging.HTML_MIME_TYPE, @@ -1302,7 +1303,7 @@ public class IrcStack // Jitsi set up. final String user = msg.getSource().getNick(); final String text = - Utils.formatNotice(Utils.parseIrcMessage(msg.getText()), user); + Utils.styleAsNotice(Utils.parseIrcMessage(msg.getText()), user); final MessageIrcImpl message = new MessageIrcImpl(text, OperationSetBasicInstantMessaging.HTML_MIME_TYPE, @@ -1326,7 +1327,7 @@ public class IrcStack { final String user = msg.getSource().getNick(); final String text = - Utils.formatAction(Utils.parseIrcMessage(msg.getText()), user); + Utils.styleAsAction(Utils.parseIrcMessage(msg.getText()), user); final MessageIrcImpl message = new MessageIrcImpl(text, OperationSetBasicInstantMessaging.HTML_MIME_TYPE, @@ -1707,7 +1708,8 @@ public class IrcStack return; } - String text = Utils.formatMessage(Utils.parseIrcMessage(msg.getText())); + String text = + Utils.styleAsMessage(Utils.parseIrcMessage(msg.getText())); MessageIrcImpl message = new MessageIrcImpl(text, "text/html", "UTF-8", null); ChatRoomMemberIrcImpl member = @@ -1736,7 +1738,8 @@ public class IrcStack new ChatRoomMemberIrcImpl(IrcStack.this.provider, this.chatroom, userNick, ChatRoomMemberRole.MEMBER); String text = - Utils.formatAction(Utils.parseIrcMessage(msg.getText()), userNick); + Utils.styleAsAction(Utils.parseIrcMessage(msg.getText()), + userNick); MessageIrcImpl message = new MessageIrcImpl(text, "text/html", "UTF-8", null); this.chatroom.fireMessageReceivedEvent(message, member, new Date(), @@ -1761,7 +1764,8 @@ public class IrcStack new ChatRoomMemberIrcImpl(IrcStack.this.provider, this.chatroom, userNick, ChatRoomMemberRole.MEMBER); final String text = - Utils.formatNotice(Utils.parseIrcMessage(msg.getText()), userNick); + Utils.styleAsNotice(Utils.parseIrcMessage(msg.getText()), + userNick); final MessageIrcImpl message = new MessageIrcImpl(text, "text/html", "UTF-8", null); this.chatroom.fireMessageReceivedEvent(message, member, new Date(), diff --git a/src/net/java/sip/communicator/impl/protocol/irc/Utils.java b/src/net/java/sip/communicator/impl/protocol/irc/Utils.java index 00550aa..d033947 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/Utils.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/Utils.java @@ -8,6 +8,8 @@ package net.java.sip.communicator.impl.protocol.irc; import net.java.sip.communicator.util.*; +import org.apache.commons.lang3.*; + /** * Some IRC-related utility methods. * @@ -114,8 +116,8 @@ public final class Utils builder.cancelAll(); break; default: - // value is a normal character, just append - builder.append(val); + // value is a normal character, escape html entities and append + builder.append(StringEscapeUtils.escapeHtml4("" + val)); break; } } @@ -192,9 +194,8 @@ public final class Utils * @param message original IRC message * @return returns HTML-formatted normal message */ - public static String formatMessage(final String message) + public static String styleAsMessage(final String message) { - // FIXME html entity encoding return message; } @@ -205,9 +206,8 @@ public final class Utils * @param user user nick name * @return returns HTML-formatted notice */ - public static String formatNotice(final String message, final String user) + public static String styleAsNotice(final String message, final String user) { - // FIXME html entity encoding return "<i>" + user + "</i>: " + message; } @@ -218,9 +218,8 @@ public final class Utils * @param user user nick name * @return returns HTML-formatted action */ - public static String formatAction(final String message, final String user) + public static String styleAsAction(final String message, final String user) { - // FIXME html entity encoding return "<b>*" + user + "</b> " + message; } } diff --git a/src/net/java/sip/communicator/impl/protocol/irc/irc.provider.manifest.mf b/src/net/java/sip/communicator/impl/protocol/irc/irc.provider.manifest.mf index 341d3ad..a28001a 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/irc.provider.manifest.mf +++ b/src/net/java/sip/communicator/impl/protocol/irc/irc.provider.manifest.mf @@ -21,4 +21,5 @@ Import-Package: org.osgi.framework, com.ircclouds.irc.api.domain.messages, com.ircclouds.irc.api.domain.messages.interfaces, com.ircclouds.irc.api.listeners, - com.ircclouds.irc.api.state + com.ircclouds.irc.api.state, + org.apache.commons.lang3 diff --git a/test/net/java/sip/communicator/impl/protocol/irc/UtilsTest.java b/test/net/java/sip/communicator/impl/protocol/irc/UtilsTest.java index b38454e..92b6ed8 100644 --- a/test/net/java/sip/communicator/impl/protocol/irc/UtilsTest.java +++ b/test/net/java/sip/communicator/impl/protocol/irc/UtilsTest.java @@ -14,16 +14,6 @@ public class UtilsTest extends TestCase { - protected void setUp() throws Exception - { - super.setUp(); - } - - protected void tearDown() throws Exception - { - super.tearDown(); - } - public void testNullText() { Assert.assertEquals(null, Utils.parseIrcMessage(null)); @@ -183,26 +173,33 @@ public class UtilsTest final String htmlMessage = "<font color=\"Navy\">With color</font> and without color."; Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage)); } + + public void testMessageContainingHtmlEntities() + { + final String ircMessage = "\u0002This<b> is very</b> bad &&& text!!!<!-- \u0002<i>"; + final String parsedMessage = "<b>This<b> is very</b> bad &&& text!!!<!-- </b><i>"; + Assert.assertEquals(parsedMessage, Utils.parseIrcMessage(ircMessage)); + } - public void testFormatMessage() + public void testStyleAsMessage() { String message = "hello world"; - Assert.assertEquals(message, Utils.formatMessage(message)); + Assert.assertEquals(message, Utils.styleAsMessage(message)); } - public void testFormatNotice() + public void testStyleAsNotice() { String message = "hello world"; String nick = "MrNiceGuy"; Assert.assertEquals("<i>MrNiceGuy</i>: hello world", - Utils.formatNotice(message, nick)); + Utils.styleAsNotice(message, nick)); } - public void testFormatAction() + public void testStyleAsAction() { String message = "is absolutely crazy!"; String nick = "AbsoluteLunatic"; Assert.assertEquals("<b>*AbsoluteLunatic</b> is absolutely crazy!", - Utils.formatAction(message, nick)); + Utils.styleAsAction(message, nick)); } } |