golang / go

The Go programming language

Home Page:https://go.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

regexp: LiteralPrefix returns complete=true incorrectly

dvyukov opened this issue · comments

The following program fails:

package main

import "regexp"

func main() {
    re := regexp.MustCompile("^0^000000$")
    prefix, complete := re.LiteralPrefix()
    if complete && !re.MatchString(prefix) {
        panic("prefix:" + prefix)
    }
}
panic: prefix:0

If LiteralPrefix return complete==true, the re must match the prefix.

go version devel +b0532a9 Mon Jun 8 05:13:15 2015 +0000 linux/amd64

This one is a real problem.

CL https://golang.org/cl/16200 mentions this issue.