-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Description
The SplitFunc in the emptyFinalToken example for bufio.Scanner doesn't handle the case of requesting more data if necessary.
The example only happens to work because the whole input is returned by a single call to Read (it uses a strings.Reader).
This should be enough to fix it:
@@ -21,7 +21,10 @@
// There is one final token to be delivered, which may be the empty string.
// Returning bufio.ErrFinalToken here tells Scan there are no more tokens after this
// but does not trigger an error to be returned from Scan itself.
- return 0, data, bufio.ErrFinalToken
+ if atEOF {
+ return 0, data, bufio.ErrFinalToken
+ }
+ return 0, nil, nil
}
scanner.Split(onComma)
// Scan.The problem is demonstrated here:
https://play.golang.org/p/CM-sWovg8mg
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.