regexp: LiteralPrefix lies about completeness
dvyukov opened this issue · 3 comments
dvyukov commented
The following program fails with the panic:
package main
import "regexp"
func main() {
re := regexp.MustCompile("^")
prefix, complete := re.LiteralPrefix()
if !complete && re.MatchString(prefix) {
panic("bad")
}
}
If complete is false, Match must fail.
go version devel +b0532a9 Mon Jun 8 05:13:15 2015 +0000 linux/amd64
cespare commented
If complete is false, Match must fail.
Why? A match doesn't have to match the entire input.
dvyukov commented
It's the other way around here. In your example, there is leftover in the string. In my example, there is leftover in the regexp (according to LiteralPrefix).
rsc commented
If complete is false, Match must fail.
Not true. If complete is false it means that there is something to the regexp beyond what has been returned in 'prefix'.