diff options
| author | Gustav Westling <zegl@westling.xyz> | 2018-05-09 19:05:46 +0000 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2018-05-09 22:10:32 +0000 |
| commit | 10529a01fd8b0d5cc07eb3f6aa00a0272597684b (patch) | |
| tree | e002a0fdd1142358e24f5f0207ba5b8dea27dbe5 /src/encoding/base32/base32_test.go | |
| parent | 0f2d4d00088486297d013fce6235ad0ac01f033e (diff) | |
| download | go-10529a01fd8b0d5cc07eb3f6aa00a0272597684b.tar.xz | |
encoding/base32: handle NoPadding when using buffered encoding in Close
This changes makes encoder.Close aware of how many bytes to write if there
is any data left in the buffer.
Fixes #25295
Change-Id: I4138891359935509cb561c453b8059ba2b9e576b
GitHub-Last-Rev: f374096d2f3cae8635506074f59e1cd440c14844
GitHub-Pull-Request: golang/go#25316
Reviewed-on: https://go-review.googlesource.com/112515
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/encoding/base32/base32_test.go')
| -rw-r--r-- | src/encoding/base32/base32_test.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/encoding/base32/base32_test.go b/src/encoding/base32/base32_test.go index 094ac288d6..fdd862dc49 100644 --- a/src/encoding/base32/base32_test.go +++ b/src/encoding/base32/base32_test.go @@ -658,3 +658,31 @@ func TestEncodedDecodedLen(t *testing.T) { }) } } + +func TestWithoutPaddingClose(t *testing.T) { + encodings := []*Encoding{ + StdEncoding, + StdEncoding.WithPadding(NoPadding), + } + + for _, encoding := range encodings { + for _, testpair := range pairs { + + var buf bytes.Buffer + encoder := NewEncoder(encoding, &buf) + encoder.Write([]byte(testpair.decoded)) + encoder.Close() + + expected := testpair.encoded + if encoding.padChar == NoPadding { + expected = strings.Replace(expected, "=", "", -1) + } + + res := buf.String() + + if res != expected { + t.Errorf("Expected %s got %s; padChar=%d", expected, res, encoding.padChar) + } + } + } +} |
