Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regexp: LiteralPrefix lies about completeness #11172

Closed
dvyukov opened this issue Jun 11, 2015 · 3 comments
Closed

regexp: LiteralPrefix lies about completeness #11172

dvyukov opened this issue Jun 11, 2015 · 3 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Jun 11, 2015

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
Copy link
Contributor

cespare commented Jun 11, 2015

If complete is false, Match must fail.

Why? A match doesn't have to match the entire input.

http://play.golang.org/p/E4iOdS7Av0

@dvyukov
Copy link
Member Author

dvyukov commented Jun 11, 2015

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).

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Jun 11, 2015
@rsc
Copy link
Contributor

rsc commented Oct 14, 2015

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'.

@rsc rsc closed this as completed Oct 14, 2015
@golang golang locked and limited conversation to collaborators Oct 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants