From: Zefram <zefram@fysh.org>
Date: Fri, 23 Oct 2009 09:13:21 +0000 (+0200)
Subject: a2p match() faulty
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6cf7238579bd512306a71f8d84f26589241691ff;p=p5sagit%2Fp5-mst-13.2.git

a2p match() faulty

While I was doing the $[ thing, I discovered a bug in a2p's handling of
the match() operator.  It uses a comma operator, which has unintended
behaviour in list context (e.g., in a print statement).  It also returns
empty string for a non-match, rather than the required 0.
---

diff --git a/x2p/walk.c b/x2p/walk.c
index 2890375..86419c1 100644
--- a/x2p/walk.c
+++ b/x2p/walk.c
@@ -725,7 +725,7 @@ sub Pick {\n\
 	str_cat(str," =~ ");
 	str_scat(str,fstr=walk(1,level,ops[node+2].ival,&numarg,P_MATCH+1));
 	str_free(fstr);
-	str_cat(str," && ($RLENGTH = length($&), $RSTART = length($`)+1)");
+	str_cat(str," ? scalar($RLENGTH = length($&), $RSTART = length($`)+1) : 0");
 	numeric = 1;
 	break;
     case OUSERDEF: