Fix INFO_ARG parsing

In split buffer conditions, a buffer is used to accumulate bytes.
After processing, this buffer needs to be reset.

Resolves #270
This commit is contained in:
Ivan Kozlovic
2016-05-11 15:51:29 -06:00
parent 26caad27c1
commit a8ff707aff
2 changed files with 10 additions and 1 deletions

View File

@@ -540,6 +540,7 @@ func (c *client) parse(buf []byte) error {
var arg []byte
if c.argBuf != nil {
arg = c.argBuf
c.argBuf = nil
} else {
arg = buf[c.as : i-c.drop]
}

View File

@@ -314,7 +314,7 @@ func TestSplitDanglingArgBuf(t *testing.T) {
c.parse(pubop[:22])
c.parse(pubop[22:25])
if c.argBuf == nil {
t.Fatal("Expected a nil argBuf!")
t.Fatal("Expected a non-nil argBuf!")
}
c.parse(pubop[25:])
if c.argBuf != nil {
@@ -337,6 +337,14 @@ func TestSplitDanglingArgBuf(t *testing.T) {
if c.argBuf != nil {
t.Fatalf("Expected c.argBuf to be nil: %q\n", c.argBuf)
}
// INFO_ARG
infoop := []byte("INFO {\"server_id\":\"id\"}\r\n")
c.parse(infoop[:8])
c.parse(infoop[8:])
if c.argBuf != nil {
t.Fatalf("Expected c.argBuf to be nil: %q\n", c.argBuf)
}
}
func TestSplitMsgArg(t *testing.T) {