]> Cypherpunks repositories - gostls13.git/commitdiff
compress/flate: don't ignore dict in Reader.Reset
authorVladimir Mihailenco <vladimir.webdev@gmail.com>
Thu, 23 Jun 2016 07:42:22 +0000 (07:42 +0000)
committerJoe Tsai <thebrokentoaster@gmail.com>
Mon, 27 Jun 2016 21:28:34 +0000 (21:28 +0000)
Fixes #16162.

Change-Id: I6f4ae906630079ef5fc29ee5f70e2e3d1c962170
Reviewed-on: https://go-review.googlesource.com/24390
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/compress/flate/inflate.go
src/compress/flate/inflate_test.go

index c1a4b60cd776b131931aa7ddbcc98305c4fc70a0..68cc232052bc328c6c55165e9e49cc1241a6eacf 100644 (file)
@@ -766,7 +766,7 @@ func (f *decompressor) Reset(r io.Reader, dict []byte) error {
                dict:     f.dict,
                step:     (*decompressor).nextBlock,
        }
-       f.dict.init(maxMatchOffset, nil)
+       f.dict.init(maxMatchOffset, dict)
        return nil
 }
 
index 9f25d30b35cd0684608371e9044a3ff1fd198263..e0bce71d6f2d9eda8795c95dd2df93c00df0ee3f 100644 (file)
@@ -37,3 +37,33 @@ func TestReset(t *testing.T) {
                }
        }
 }
+
+func TestResetDict(t *testing.T) {
+       dict := []byte("the lorem fox")
+       ss := []string{
+               "lorem ipsum izzle fo rizzle",
+               "the quick brown fox jumped over",
+       }
+
+       deflated := make([]bytes.Buffer, len(ss))
+       for i, s := range ss {
+               w, _ := NewWriterDict(&deflated[i], DefaultCompression, dict)
+               w.Write([]byte(s))
+               w.Close()
+       }
+
+       inflated := make([]bytes.Buffer, len(ss))
+
+       f := NewReader(nil)
+       for i := range inflated {
+               f.(Resetter).Reset(&deflated[i], dict)
+               io.Copy(&inflated[i], f)
+       }
+       f.Close()
+
+       for i, s := range ss {
+               if s != inflated[i].String() {
+                       t.Errorf("inflated[%d]:\ngot  %q\nwant %q", i, inflated[i], s)
+               }
+       }
+}