aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Mihailenco <vladimir.webdev@gmail.com>2016-06-23 07:42:22 +0000
committerJoe Tsai <thebrokentoaster@gmail.com>2016-06-27 21:28:34 +0000
commit0ce100dc9646eb9015e31502e184e45605df1393 (patch)
treec17094201ffac8ceae99b04ac0c610c01447a9f0
parentdb5802104797cadcb4f44c5198a0fc39e13f9bc3 (diff)
downloadgo-0ce100dc9646eb9015e31502e184e45605df1393.tar.gz
go-0ce100dc9646eb9015e31502e184e45605df1393.zip
compress/flate: don't ignore dict in Reader.Reset
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>
-rw-r--r--src/compress/flate/inflate.go2
-rw-r--r--src/compress/flate/inflate_test.go30
2 files changed, 31 insertions, 1 deletions
diff --git a/src/compress/flate/inflate.go b/src/compress/flate/inflate.go
index c1a4b60cd7..68cc232052 100644
--- a/src/compress/flate/inflate.go
+++ b/src/compress/flate/inflate.go
@@ -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
}
diff --git a/src/compress/flate/inflate_test.go b/src/compress/flate/inflate_test.go
index 9f25d30b35..e0bce71d6f 100644
--- a/src/compress/flate/inflate_test.go
+++ b/src/compress/flate/inflate_test.go
@@ -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)
+ }
+ }
+}