diff options
author | Rob Pike <r@golang.org> | 2009-11-23 14:06:21 -0800 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2009-11-23 14:06:21 -0800 |
commit | b551d0b68a0c5e29fc930061d0a795e4df6e27ef (patch) | |
tree | 5d55bd4eb0f9a8be73e4620d90948ded8b6d9321 /src/pkg/regexp/regexp.go | |
parent | 6fb28258ee660c99bda8706db6778a964d52abac (diff) | |
download | golang-b551d0b68a0c5e29fc930061d0a795e4df6e27ef.tar.gz |
fix bug in prefix code: must stop one character before any potential match of an empty string
Fixes issue 308.
R=rsc
CC=golang-dev
http://codereview.appspot.com/157142
Diffstat (limited to 'src/pkg/regexp/regexp.go')
-rw-r--r-- | src/pkg/regexp/regexp.go | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/pkg/regexp/regexp.go b/src/pkg/regexp/regexp.go index 8f17954d7..014a9fdc7 100644 --- a/src/pkg/regexp/regexp.go +++ b/src/pkg/regexp/regexp.go @@ -633,15 +633,18 @@ func (re *Regexp) setPrefix() { var utf = make([]byte, utf8.UTFMax); // First instruction is start; skip that. i := re.inst.At(0).(instr).next().index(); +Loop: for i < re.inst.Len() { inst := re.inst.At(i).(instr); // stop if this is not a char if inst.kind() != _CHAR { break } - // stop if this char starts a closure; liberal but easy test: is an ALT next? - if re.inst.At(inst.next().index()).(instr).kind() == _ALT { - break + // stop if this char can be followed by a match for an empty string, + // which includes closures, ^, and $. + switch re.inst.At(inst.next().index()).(instr).kind() { + case _BOT, _EOT, _ALT: + break Loop } n := utf8.EncodeRune(inst.(*_Char).char, utf); b = bytes.Add(b, utf[0:n]); |