From: Ilya Zakharevich Date: Sun, 21 Jun 1998 04:27:16 +0000 (-0400) Subject: Zero-length matching bug X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7e5428c5eadf5068dae305575a105bd61a84cb5d;p=p5sagit%2Fp5-mst-13.2.git Zero-length matching bug Message-Id: <199806210827.EAA26322@monk.mps.ohio-state.edu> p4raw-id: //depot/perl@1185 --- diff --git a/regexec.c b/regexec.c index b6d2ca4..dd51bc1 100644 --- a/regexec.c +++ b/regexec.c @@ -697,7 +697,7 @@ regtry(regexp *prog, char *startpos) } } REGCP_SET; - if (regmatch(prog->program + 1) && reginput >= regtill) { + if (regmatch(prog->program + 1)) { prog->startp[0] = startpos; prog->endp[0] = reginput; return 1; @@ -1504,8 +1504,11 @@ regmatch(regnode *prog) } sayNO; break; - case SUCCEED: case END: + if (locinput < regtill) + sayNO; /* Cannot match: too short. */ + /* Fall through */ + case SUCCEED: reginput = locinput; /* put where regtry can find it */ sayYES; /* Success! */ case SUSPEND: diff --git a/t/op/pat.t b/t/op/pat.t index 9377b99..f0bbdbc 100755 --- a/t/op/pat.t +++ b/t/op/pat.t @@ -2,7 +2,7 @@ # $RCSfile: pat.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:12 $ -print "1..108\n"; +print "1..113\n"; $x = "abc\ndef\n"; @@ -378,6 +378,22 @@ print "not " unless study(/\b\v$/) eq '\bv$'; print "ok $test\n"; $test++; +$_ = 'xabcx'; +foreach $ans ('', 'c') { + /(?<=(?=a)..)((?=c)|.)/g; + print "not " unless $1 eq $ans; + print "ok $test\n"; + $test++; +} + +$_ = 'a'; +foreach $ans ('', 'a', '') { + /^|a|$/g; + print "not " unless $& eq $ans; + print "ok $test\n"; + $test++; +} + sub must_warn_pat { my $warn_pat = shift; return sub { print "not " unless $_[0] =~ /$warn_pat/ }