Fix malformed messages parsing
authorunc0rr
Wed, 18 Jan 2017 22:23:41 +0300
changeset 12140 7e259e47eb0d
parent 12139 f3121d7dedec
child 12141 78925eff02c2
Fix malformed messages parsing
gameServer2/src/protocol/parser.rs
--- a/gameServer2/src/protocol/parser.rs	Wed Jan 18 22:15:55 2017 +0300
+++ b/gameServer2/src/protocol/parser.rs	Wed Jan 18 22:23:41 2017 +0300
@@ -111,9 +111,9 @@
         | one_param_message
         | cmd_message
         | complex_message
-        | malformed_message
         ), end_of_message
     )
+    | terminated!(malformed_message, end_of_message)
     | empty_message
     )
 );
@@ -131,6 +131,8 @@
     assert_eq!(message(b"CMD\nwatch\ndemo\n\n"), IResult::Done(&b""[..], Watch("demo")));
     assert_eq!(message(b"BAN\nme\nbad\n77\n\n"), IResult::Done(&b""[..], Ban("me", "bad", 77)));
 
+    assert_eq!(extract_messages(b"QUIT\n1\n2\n\n"),    IResult::Done(&b""[..], vec![Malformed]));
+
     assert_eq!(extract_messages(b"PING\n\nPING\n\nP"), IResult::Done(&b"P"[..], vec![Ping, Ping]));
     assert_eq!(extract_messages(b"SING\n\nPING\n\n"),  IResult::Done(&b""[..],  vec![Malformed, Ping]));
     assert_eq!(extract_messages(b"\n\n\n\nPING\n\n"),  IResult::Done(&b""[..],  vec![Empty, Empty, Ping]));