File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -103,7 +103,8 @@ func (s *Scanner) Text() string {
103103
104104// Scan advances the Scanner to the next token, which will then be
105105// available through the Bytes or Text method. It returns false when the
106- // scan stops, either by reaching the end of the input or an error.
106+ // scan stops, either by reaching the end of the input, a zero-length
107+ // read from the input, or an error.
107108// After Scan returns false, the Err method will return any error that
108109// occurred during scanning, except that if it was io.EOF, Err
109110// will return nil.
@@ -164,7 +165,7 @@ func (s *Scanner) Scan() bool {
164165 s .setErr (err )
165166 }
166167 if n == 0 { // Don't loop forever if Reader doesn't deliver EOF.
167- s .err = io .EOF
168+ s .setErr ( io .EOF )
168169 }
169170 s .end += n
170171 }
Original file line number Diff line number Diff line change @@ -368,3 +368,21 @@ func TestErrAtEOF(t *testing.T) {
368368 t .Fatal ("wrong error:" , s .Err ())
369369 }
370370}
371+
372+ // Test for issue 5268.
373+ type alwaysError struct {}
374+
375+ func (alwaysError ) Read (p []byte ) (int , error ) {
376+ return 0 , io .ErrUnexpectedEOF
377+ }
378+
379+ func TestNonEOFWithEmptyRead (t * testing.T ) {
380+ scanner := NewScanner (alwaysError {})
381+ for scanner .Scan () {
382+ t .Fatal ("read should fail" )
383+ }
384+ err := scanner .Err ()
385+ if err != io .ErrUnexpectedEOF {
386+ t .Errorf ("unexpected error: %v" , err )
387+ }
388+ }
You can’t perform that action at this time.
0 commit comments