update parser to not utf8 encode for string payloads
This commit is contained in:
@@ -156,6 +156,19 @@ public class ParserTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodingStringMessageWithLoneSurrogatesReplacedByUFFFD() throws UTF8Exception {
|
||||
String data = "\uDC00\uD834\uDF06\uDC00 \uD800\uD835\uDF07\uD800";
|
||||
encodePacket(new Packet<String>(Packet.MESSAGE, data), true, new EncodeCallback<String>() {
|
||||
@Override
|
||||
public void call(String encoded) {
|
||||
Packet<String> p = decodePacket(encoded, true);
|
||||
assertThat(p.type, is(Packet.MESSAGE));
|
||||
assertThat(p.data, is("\uFFFD\uD834\uDF06\uFFFD \uFFFD\uD835\uDF07\uFFFD"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeEmptyPayload() {
|
||||
Packet<String> p = decodePacket((String)null);
|
||||
@@ -186,20 +199,20 @@ public class ParserTest {
|
||||
|
||||
@Test
|
||||
public void encodePayloads() throws UTF8Exception {
|
||||
encodePayload(new Packet[]{new Packet(Packet.PING), new Packet(Packet.PONG)}, new EncodeCallback<byte[]>() {
|
||||
encodePayload(new Packet[]{new Packet(Packet.PING), new Packet(Packet.PONG)}, new EncodeCallback<String>() {
|
||||
@Override
|
||||
public void call(byte[] data) {
|
||||
assertThat(data, isA(byte[].class));
|
||||
public void call(String data) {
|
||||
assertThat(data, isA(String.class));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeAndDecodePayloads() throws UTF8Exception {
|
||||
encodePayload(new Packet[] {new Packet<String>(Packet.MESSAGE, "a")}, new EncodeCallback<byte[]>() {
|
||||
encodePayload(new Packet[] {new Packet<String>(Packet.MESSAGE, "a")}, new EncodeCallback<String>() {
|
||||
@Override
|
||||
public void call(byte[] data) {
|
||||
decodePayload(data, new DecodePayloadCallback() {
|
||||
public void call(String data) {
|
||||
decodePayload(data, new DecodePayloadCallback<String>() {
|
||||
@Override
|
||||
public boolean call(Packet packet, int index, int total) {
|
||||
boolean isLast = index + 1 == total;
|
||||
@@ -209,10 +222,10 @@ public class ParserTest {
|
||||
});
|
||||
}
|
||||
});
|
||||
encodePayload(new Packet[]{new Packet<String>(Packet.MESSAGE, "a"), new Packet(Packet.PING)}, new EncodeCallback<byte[]>() {
|
||||
encodePayload(new Packet[]{new Packet<String>(Packet.MESSAGE, "a"), new Packet(Packet.PING)}, new EncodeCallback<String>() {
|
||||
@Override
|
||||
public void call(byte[] data) {
|
||||
decodePayload(data, new DecodePayloadCallback() {
|
||||
public void call(String data) {
|
||||
decodePayload(data, new DecodePayloadCallback<String>() {
|
||||
@Override
|
||||
public boolean call(Packet packet, int index, int total) {
|
||||
boolean isLast = index + 1 == total;
|
||||
@@ -230,10 +243,10 @@ public class ParserTest {
|
||||
|
||||
@Test
|
||||
public void encodeAndDecodeEmptyPayloads() throws UTF8Exception {
|
||||
encodePayload(new Packet[] {}, new EncodeCallback<byte[]>() {
|
||||
encodePayload(new Packet[] {}, new EncodeCallback<String>() {
|
||||
@Override
|
||||
public void call(byte[] data) {
|
||||
decodePayload(data, new DecodePayloadCallback() {
|
||||
public void call(String data) {
|
||||
decodePayload(data, new DecodePayloadCallback<String>() {
|
||||
@Override
|
||||
public boolean call(Packet packet, int index, int total) {
|
||||
assertThat(packet.type, is(Packet.OPEN));
|
||||
@@ -246,6 +259,19 @@ public class ParserTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notUTF8EncodeWhenDealingWithStringsOnly() throws UTF8Exception {
|
||||
encodePayload(new Packet[] {
|
||||
new Packet(Packet.MESSAGE, "€€€"),
|
||||
new Packet(Packet.MESSAGE, "α")
|
||||
}, new EncodeCallback<String>() {
|
||||
@Override
|
||||
public void call(String data) {
|
||||
assertThat(data, is("4:4€€€2:4α"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodePayloadBadFormat() {
|
||||
decodePayload("1!", new DecodePayloadCallback<String>() {
|
||||
@@ -328,20 +354,6 @@ public class ParserTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodePayloadInvalidUTF8() {
|
||||
decodePayload("2:4\uffff", new DecodePayloadCallback<String>() {
|
||||
@Override
|
||||
public boolean call(Packet<String> packet, int index, int total) {
|
||||
boolean isLast = index + 1 == total;
|
||||
assertThat(packet.type, is(Packet.ERROR));
|
||||
assertThat(packet.data, is(ERROR_DATA));
|
||||
assertThat(isLast, is(true));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeBinaryMessage() throws UTF8Exception {
|
||||
final byte[] data = new byte[5];
|
||||
|
||||
Reference in New Issue
Block a user