[ic] It seems that [if]tag return nothing when result is 0.

Jon Jensen interchange-users@interchange.redhat.com
Mon Mar 11 12:26:02 2002


On Mon, 11 Mar 2002, murahashi wrote:

> I have strange behavior of [if] tag below.
> I want to have 0 or 1 from the following sample.
> In case of A or B , It works.
> It seems that [if]tag return nothing when result is 0.
> Is that right? Am I something wrong?

It looks like you found a bug in the [if] tag when using [else]0[/else].
Following is a patch against Interchange 4.9 in CVS, which I'll commit to
CVS.

Thanks!
Jon


Index: Parse.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Parse.pm,v
retrieving revision 2.15
diff -u -r2.15 Parse.pm
--- Parse.pm	4 Mar 2002 23:45:17 -0000	2.15
+++ Parse.pm	11 Mar 2002 17:22:33 -0000
@@ -674,7 +674,7 @@
 			$tmpbuf = $p->{ABORT} ? '' : $p->{OUT};
 		}
 		if($attr->{reparse} ) {
-			$$buf = ($routine->(@args,$tmpbuf) || '') . $$buf;
+			$$buf = ($routine->(@args,$tmpbuf)) . $$buf;
 		}
 		else {
 			$self->{OUT} .= &{$routine}(@args,$tmpbuf);
Index: Interpolate.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.61
diff -u -r2.61 Interpolate.pm
--- Interpolate.pm	28 Feb 2002 17:32:15 -0000	2.61
+++ Interpolate.pm	11 Mar 2002 17:22:35 -0000
@@ -1470,11 +1470,11 @@
 		$out = $body;
 	}
 	elsif ($elsif) {
-		$else = '[else]' . $else . '[/else]' if $else;
+		$else = '[else]' . $else . '[/else]' if length $else;
 		$elsif =~ s#(.*?)$QR{'/elsif'}(.*)#$1${2}[/elsif]#s;
 		$out = '[if ' . $elsif . $else . '[/if]';
 	}
-	elsif ($else) {
+	elsif (length $else) {
 		$out = $else;
 	}
 	return $out;
@@ -3103,11 +3103,11 @@
 		$out = $body;
 	}
 	elsif ($elsif) {
-		$else = '[else]' . $else . '[/else]' if $else;
+		$else = '[else]' . $else . '[/else]' if length $else;
 		$elsif =~ s#(.*?)$QR{'/elsif'}(.*)#$1${2}[/elsif]#s;
 		$out = '[if ' . $elsif . $else . '[/if]';
 	}
-	elsif ($else) {
+	elsif (length $else) {
 		$out = $else;
 	}
 	else {