Previously this case was hidden because ReadString() can return a string
and an EOF error. To prevent this issue from going unnoticed error out.
t, err := s.ReadString('\n')
if err != nil {
if err == io.EOF {
t, err := s.ReadString('\n')
if err != nil {
if err == io.EOF {
+ if t != "" {
+ return nil, fmt.Errorf(
+ "no newline in last line: %q",
+ t)
+ }
"reflect"
"strings"
"testing"
"reflect"
"strings"
"testing"
tests := []struct {
data string
exp []Group
tests := []struct {
data string
exp []Group
+ nil,
+ },
+ {
+ "root:x:0:",
+ nil,
+ fmt.Errorf("no newline in last line: \"root:x:0:\""),
},
{
"root:x:0:foo,bar\n",
},
{
"root:x:0:foo,bar\n",
},
}
for n, tc := range tests {
res, err := ParseGroups(strings.NewReader(tc.data))
},
}
for n, tc := range tests {
res, err := ParseGroups(strings.NewReader(tc.data))
+ if !reflect.DeepEqual(err, tc.err) {
t.Errorf("%d: err = %v, want %v",
t.Errorf("%d: err = %v, want %v",
}
if !reflect.DeepEqual(res, tc.exp) {
t.Errorf("%d: res = %v, want %v",
}
if !reflect.DeepEqual(res, tc.exp) {
t.Errorf("%d: res = %v, want %v",
t, err := s.ReadString('\n')
if err != nil {
if err == io.EOF {
t, err := s.ReadString('\n')
if err != nil {
if err == io.EOF {
+ if t != "" {
+ return nil, fmt.Errorf(
+ "no newline in last line: %q",
+ t)
+ }