parser: check empty arg

This commit is contained in:
nkzawa
2017-07-11 18:16:49 +09:00
parent b2798fe85d
commit 115f32171d
2 changed files with 11 additions and 0 deletions

View File

@@ -76,6 +76,10 @@ public class Parser {
} }
public static Packet<String> decodePacket(String data, boolean utf8decode) { public static Packet<String> decodePacket(String data, boolean utf8decode) {
if (data == null) {
return err;
}
int type; int type;
try { try {
type = Character.getNumericValue(data.charAt(0)); type = Character.getNumericValue(data.charAt(0));

View File

@@ -156,6 +156,13 @@ public class ParserTest {
}); });
} }
@Test
public void decodeEmptyPayload() {
Packet<String> p = decodePacket((String)null);
assertThat(p.type, is(Packet.ERROR));
assertThat(p.data, is(ERROR_DATA));
}
@Test @Test
public void decodeBadFormat() { public void decodeBadFormat() {
Packet<String> p = decodePacket(":::"); Packet<String> p = decodePacket(":::");