parser: check empty arg
This commit is contained in:
@@ -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));
|
||||||
|
|||||||
@@ -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(":::");
|
||||||
|
|||||||
Reference in New Issue
Block a user