diff options
| author | Rui Ueyama <ruiu@google.com> | 2014-03-18 20:52:58 -0700 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2014-03-18 20:52:58 -0700 |
| commit | 1a21dbc5720326b0e325a54c3e01c0e50b32eb03 (patch) | |
| tree | 89850483dfa45085a0a4bcb454f01c0b3422ef14 /src/pkg/bytes/bytes_test.go | |
| parent | f34251a91c2d075def51b763c52a0c602f3e09c9 (diff) | |
| download | go-1a21dbc5720326b0e325a54c3e01c0e50b32eb03.tar.xz | |
bytes: fix panic in Map
utf8.RuneLen returns -1 for an invalid rune. In that case we
need to extend the internal buffer at least by 3 for \uFFFD.
Fixes #7577.
LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/77420044
Diffstat (limited to 'src/pkg/bytes/bytes_test.go')
| -rw-r--r-- | src/pkg/bytes/bytes_test.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/pkg/bytes/bytes_test.go b/src/pkg/bytes/bytes_test.go index 808655a4a4..b16ac9f515 100644 --- a/src/pkg/bytes/bytes_test.go +++ b/src/pkg/bytes/bytes_test.go @@ -785,6 +785,16 @@ func TestMap(t *testing.T) { if string(m) != expect { t.Errorf("drop: expected %q got %q", expect, m) } + + // 6. Invalid rune + invalidRune := func(r rune) rune { + return utf8.MaxRune + 1 + } + m = Map(invalidRune, []byte("x")) + expect = "\uFFFD" + if string(m) != expect { + t.Errorf("invalidRune: expected %q got %q", expect, m) + } } func TestToUpper(t *testing.T) { runStringTests(t, ToUpper, "ToUpper", upperTests) } |
