-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.release-blocker
Milestone
Description
What did you do?
On a bufio.Reader, invoke ReadByte, then Discard one or more bytes, then UnreadByte (https://play.golang.org/p/RTitxKuiikQ):
package main
import (
"bufio"
"strings"
"testing"
)
func TestBytesBufferUnreadByte(t *testing.T) {
check := func(err error) {
if err != nil {
t.Helper()
t.Fatal(err)
}
}
const in = "abc\n"
t.Logf("reading %q", in)
b := bufio.NewReader(strings.NewReader(in))
c, err := b.ReadByte()
check(err)
t.Logf("read byte %q", c)
n, err := b.Discard(1)
check(err)
t.Logf("discarded %v byte(s)", n)
err = b.UnreadByte()
t.Logf("UnreadByte: %v", err)
var want string
if err == nil {
want = in[1:]
} else {
want = in[2:]
}
s, err := b.ReadString('\n')
check(err)
if s != want {
t.Fatalf("buffer corrupted: read %q, expected %q", s, want)
}
}What did you expect to see?
UnreadByte after Discard either restores the last discarded byte, or returns a non-nil error and does not modify the buffered data.
What did you see instead?
UnreadByte overwrites the last discarded byte with the last byte returned from the last Read* call.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.release-blocker