Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public Packet<?> decodePacket(Object data) {
final String stringData = (String) data;
if(stringData.charAt(0) == 'b') {
final Packet<byte[]> packet = new Packet<>(Packet.MESSAGE);
packet.data = java.util.Base64.getDecoder().decode(stringData.substring(1));
// Ignore line breaks, added by engine.io-client-java during base64 encode
packet.data = java.util.Base64.getDecoder().decode(stringData.substring(1).replace("\n", ""));
return packet;
} else {
final Packet<String> packet = new Packet<>(PACKETS_REVERSE.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ public void testDecodePacket_base64() {
assertEquals(byte[].class, packetDecoded.data.getClass());
assertArrayEquals(packetOriginal.data, (byte[]) packetDecoded.data);
});

// Other socket.io libraries may add a line break to their base64 encoded output
final Packet<byte[]> packetOriginalLineBreak = new Packet<>(Packet.MESSAGE, "Engine.IO".getBytes(StandardCharsets.UTF_8));
Parser.PROTOCOL_V4.encodePacket(packetOriginalLineBreak, false, data -> {
data += "\n";
Packet<?> packetDecoded = Parser.PROTOCOL_V4.decodePacket(data);
assertEquals(Packet.MESSAGE, packetDecoded.type);
assertEquals(byte[].class, packetDecoded.data.getClass());
assertArrayEquals(packetOriginal.data, (byte[]) packetDecoded.data);
});
}

@Test(expected = IllegalArgumentException.class)
Expand Down Expand Up @@ -301,4 +311,4 @@ public void testDecodePayload_exit() {
});
});
}
}
}