From 0f1b5faf6fb47404c56dc14cbe79e25f30d5a51c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 27 Apr 2015 19:15:53 +0200 Subject: [PATCH] Escape the input, not the output --- .../net/pterodactylus/irc/DefaultConnection.java | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/pterodactylus/irc/DefaultConnection.java b/src/main/java/net/pterodactylus/irc/DefaultConnection.java index 194caf7..dd6955c 100644 --- a/src/main/java/net/pterodactylus/irc/DefaultConnection.java +++ b/src/main/java/net/pterodactylus/irc/DefaultConnection.java @@ -316,7 +316,7 @@ public class DefaultConnection extends AbstractExecutionThreadService implements while (connected) { Reply reply = connectionHandler.readReply(); eventBus.post(new ReplyReceived(this, reply)); - logger.trace(String.format("<< %s", reply)); + logger.trace(String.format("<< %s", addEscapeCharacters(reply.toString()))); String command = reply.command(); List parameters = reply.parameters(); @@ -378,6 +378,18 @@ public class DefaultConnection extends AbstractExecutionThreadService implements // PRIVATE METHODS // + private String addEscapeCharacters(String line) { + StringBuilder escaped = new StringBuilder(); + for (char c : line.toCharArray()) { + if (c < 32) { + escaped.append("\\CTRL[").append((int) c).append("]"); + } else { + escaped.append(c); + } + } + return escaped.toString(); + } + /** * Returns an item from the list, or {@link Optional#empty()} if the list is * shorter than required for the given index. @@ -500,23 +512,11 @@ public class DefaultConnection extends AbstractExecutionThreadService implements commandBuilder.append(parameter); } - logger.trace(String.format(">> %s", addEscapeCharacters(commandBuilder))); + logger.trace(String.format(">> %s", commandBuilder)); outputStream.write((commandBuilder.toString() + "\r\n").getBytes("UTF-8")); outputStream.flush(); } - private String addEscapeCharacters(StringBuilder commandBuilder) { - StringBuilder escaped = new StringBuilder(); - for (char c : commandBuilder.toString().toCharArray()) { - if (c < 32) { - escaped.append("\\CTRL[").append((int) c).append("]"); - } else { - escaped.append(c); - } - } - return escaped.toString(); - } - /** * Reads a line of reply from the connection. * -- 2.7.4