Merge pull request #186 from wallyqs/unsub-spc-state

Add UNSUB_SPC parser state
This commit is contained in:
Derek Collison
2016-02-03 18:53:36 -08:00
2 changed files with 36 additions and 0 deletions

View File

@@ -66,6 +66,7 @@ const (
OP_UNS
OP_UNSU
OP_UNSUB
OP_UNSUB_SPC
UNSUB_ARG
OP_M
OP_MS
@@ -304,6 +305,13 @@ func (c *client) parse(buf []byte) error {
goto parseErr
}
case OP_UNSUB:
switch b {
case ' ', '\t':
c.state = OP_UNSUB_SPC
default:
goto parseErr
}
case OP_UNSUB_SPC:
switch b {
case ' ', '\t':
continue

View File

@@ -380,6 +380,34 @@ func TestShouldFail(t *testing.T) {
if err := c.parse([]byte("PUB foo 2\r\nok\r \n")); err == nil {
t.Fatal("Should have received a parse error")
}
c.state = OP_START
if err := c.parse([]byte("UNSUBUNSUB 1\r\n")); err == nil {
t.Fatal("Should have received a parse error")
}
c.state = OP_START
if err := c.parse([]byte("UNSUB_2\r\n")); err == nil {
t.Fatal("Should have received a parse error")
}
c.state = OP_START
if err := c.parse([]byte("UNSUB_UNSUB_UNSUB 2\r\n")); err == nil {
t.Fatal("Should have received a parse error")
}
c.state = OP_START
if err := c.parse([]byte("UNSUB_\t2\r\n")); err == nil {
t.Fatal("Should have received a parse error")
}
c.state = OP_START
if err := c.parse([]byte("UNSUB\r\n")); err == nil {
t.Fatal("Should have received a parse error")
}
c.state = OP_START
if err := c.parse([]byte("UNSUB \r\n")); err == nil {
t.Fatal("Should have received a parse error")
}
c.state = OP_START
if err := c.parse([]byte("UNSUB \t \r\n")); err == nil {
t.Fatal("Should have received a parse error")
}
}
func TestProtoSnippet(t *testing.T) {