regexp: RuneReader-related functions treat non-EOF errors the same as EOF #40509
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, go1.14.6.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Preamble: Sorry if this is known behavior for the
regexp
package. It was not obvious to me after reading the documentation.I provided
regexp.MatchReader
with aRuneReader
that always returns a non-EOF error (https://play.golang.org/p/_CVP4uouxy4):What did you expect to see?
I expected
regexp.MatchReader
to return a non-nil error because the underlyingRuneReader
had an error.What did you see instead?
regexp.MatchReader
returnedfalse
(no match) and a nil error.I also noticed the
*Regexp
methods that take aRuneReader
do not return errors. I doubt much can be done about that other than potentially some documentation improvements.I'm not sure if anything should be done about
regexp.MatchReader
but since the signature has an error it may be surprising that it only returns an error if the provided regular expression does not compile, not if theRuneReader
has an error. If the behavior cannot be changed it might be good to have some documentation to let people knowregexp.MatchReader
may return false because all of the input was not available due to an error.I was able to work around the issue by wrapping the rune reader and snooping on the results (https://play.golang.org/p/X-u5lkZ6hXw).
The text was updated successfully, but these errors were encountered: