Atmosphere / wasync

WebSockets with fallback transports client library for Node.js, Android and Java
http://async-io.org
161 stars 47 forks source link

TrackMessageSizeDecoder is aborting messages that contain "__" in the body #148

Closed galvo closed 7 years ago

galvo commented 7 years ago

TrackMessageSizeDecoder replaces the default delimiter "|" with "". This will then result in the discarding of any messages whose contents contains "" anywhere in its body and this message will be aborted and considered to be "fully decoded" by the TrackMessageSizeDecoder and will therefore never be triggered to any client functions.

I can recreate this with by adding the following testBadNotification unit test within TrackMessageSizeDecoderTest

@Test
/* This test will pass */
public void testGoodNotification() {
    decoder = new TrackMessageSizeDecoder(DELIMITER, false);
    String message = "36|{\n   \"id\" : \"G1JclURxSyAgLX8O5zgw\"\n}";
    List<String> expected = new ArrayList<String>() {
        {
            add("{\n   \"id\" : \"G1JclURxSyAgLX8O5zgw\"\n}");
        }
    };
    Decoded<List<String>> result = decoder.decode(Event.MESSAGE, message);
    assertEquals(result.decoded(), expected);
}

@Test
/* This test will fail due the JSON id containing "__" */
public void testBadNotification() {
    decoder = new TrackMessageSizeDecoder(DELIMITER, false);
    String message = "38|{\n   \"id\" : \"G1J__clURxSyAgLX8O5zgw\"\n}";
    List<String> expected = new ArrayList<String>() {
        {
            add("{\n   \"id\" : \"G1J__clURxSyAgLX8O5zgw\"\n}");
        }
    };
    Decoded<List<String>> result = decoder.decode(Event.MESSAGE, message);
    assertEquals(result.decoded(), expected);
}