[interchange-cvs] interchange - jon modified 2 files

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Mon Feb 16 16:25:11 EST 2004


User:      jon
Date:      2004-02-16 21:25:11 GMT
Modified:  lib/Vend Interpolate.pm
Modified:  dist/test/products tests.asc
Log:
Fix rare but nasty bug that causes chained ITL conditional tests to fail
in no-op mode:

	[if scratch something][or value something]...[/if]
	[if scratch something][and value something]...[/if]

Tests included.

The problem happens when the first [if] contains a string that doesn't
convert nicely to a number, and gets passed to an XOR test directly instead
of being converted to a 1 or 0 first. That causes a string XOR to be done,
which gives the wrong answer.

Since this is a sensitive area of code, I'd appreciate others checking it
out.

Revision  Changes    Path
2.204     +6 -6      interchange/lib/Vend/Interpolate.pm


rev 2.204, prev_rev 2.203
Index: Interpolate.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.203
retrieving revision 2.204
diff -u -u -r2.203 -r2.204
--- Interpolate.pm	4 Feb 2004 23:45:39 -0000	2.203
+++ Interpolate.pm	16 Feb 2004 21:25:10 -0000	2.204
@@ -1,6 +1,6 @@
 # Vend::Interpolate - Interpret Interchange tags
 # 
-# $Id: Interpolate.pm,v 2.203 2004/02/04 23:45:39 edl Exp $
+# $Id: Interpolate.pm,v 2.204 2004/02/16 21:25:10 jon Exp $
 #
 # Copyright (C) 2002-2003 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -28,7 +28,7 @@
 require Exporter;
 @ISA = qw(Exporter);
 
-$VERSION = substr(q$Revision: 2.203 $, 10);
+$VERSION = substr(q$Revision: 2.204 $, 10);
 
 @EXPORT = qw (
 
@@ -1433,11 +1433,11 @@
 
 	RUNSAFE: {
 		last RUNSAFE if defined $status;
-		last RUNSAFE if $status = ($noop && $op);
+		last RUNSAFE if $status = ($noop && $op) ? 1 : 0;
 		$ready_safe->trap(@{$Global::SafeTrap});
 		$ready_safe->untrap(@{$Global::SafeUntrap});
-		$status = $ready_safe->reval($op)
-			unless ($@ or $status);
+		$status = $ready_safe->reval($op) ? 1 : 0
+			unless $@;
 		if ($@) {
 			logError qq%Bad if '@_': $@%;
 			$status = 0;
@@ -1449,7 +1449,7 @@
 	for(@addl) {
 		my $chain = /^\[[Aa]/;
 		last if ($chain ^ $status);
-		$status = ${(new Vend::Parse)->parse($_)->{OUT}};
+		$status = ${(new Vend::Parse)->parse($_)->{OUT}} ? 1 : 0;
 	}
 #::logDebug("if status=$status");
 



2.14      +50 -8     interchange/dist/test/products/tests.asc


rev 2.14, prev_rev 2.13
Index: tests.asc
===================================================================
RCS file: /var/cvs/interchange/dist/test/products/tests.asc,v
retrieving revision 2.13
retrieving revision 2.14
diff -u -u -r2.13 -r2.14
--- tests.asc	4 Dec 2003 02:31:18 -0000	2.13
+++ tests.asc	16 Feb 2004 21:25:11 -0000	2.14
@@ -2380,20 +2380,62 @@
 %%
 Test local date-based counter with alpha start, test rollover
 %%%
-999999
+000152
 %%
-[the test] [perl]
-# Make this come out right
-return 'The expected result as a regex.';
-[/perl]
+[calc interpolate=0]
+	$CGI->{somecgi1} = '1 2 3 4';
+	$CGI->{somecgi2} = 1;
+	$CGI->{somecgi3} = 1234;
+	$CGI->{somecgi4} = 'a1234';
+	delete $CGI->{nocgi};
+	return;
+[/calc]
+1=[if cgi somecgi1]true[else]false[/else][/if]
+2=[if cgi somecgi1][or cgi nocgi]true[else]false[/else][/if]
+3=[if cgi somecgi1][and cgi nocgi]true[else]false[/else][/if]
+4=[if cgi somecgi1][or cgi somecgi1]true[else]false[/else][/if]
+5=[if cgi somecgi1][and cgi somecgi1]true[else]false[/else][/if]
+6=[if cgi somecgi1][or cgi nocgi][or cgi somecgi2]true[else]false[/else][/if]
+7=[if cgi nocgi][or cgi somecgi2]true[else]false[/else][/if]
+8=[if cgi nocgi][or cgi nocgi][or cgi somecgi2]true[else]false[/else][/if]
+9=[if cgi nocgi][or cgi nocgi][or cgi nocgi]true[else]false[/else][/if]
+10=[if cgi somecgi2][or cgi nocgi]true[else]false[/else][/if]
+11=[if cgi somecgi3][or cgi nocgi]true[else]false[/else][/if]
+12=[if cgi somecgi4][and cgi nocgi]true[else]false[/else][/if]
+13=[if cgi somecgi4][or cgi nocgi]true[else]false[/else][/if]
+14=[if cgi somecgi4][or cgi nocgi][or cgi somecgi3]true[else]false[/else][/if]
+15=[if cgi somecgi4][or cgi nocgi][or cgi somecgi4]true[else]false[/else][/if]
+16=[if cgi somecgi4][or cgi somecgi4]true[else]false[/else][/if]
+17=[if cgi somecgi4][or cgi somecgi4][or cgi somecgi4]true[else]false[/else][/if]
+18=[if cgi nocgi][or cgi nocgi]true[else]false[/else][/if]
+19=[if cgi nocgi][or cgi somecgi4]true[else]false[/else][/if]
+20=[if cgi nocgi][or cgi somecgi4][or cgi nocgi]true[else]false[/else][/if]
 %%
-The expected result as a regex.
+1=true
+2=true
+3=false
+4=true
+5=true
+6=true
+7=true
+8=true
+9=false
+10=true
+11=true
+12=false
+13=true
+14=true
+15=true
+16=true
+17=true
+18=false
+19=true
+20=true
 %%
-The NOT expected result.
 %%
 
 %%
-Skeleton test.
+Test chained tag-based conditionals, e.g. [if ...][or ...]...[/if]
 %%%
 999999
 %%








More information about the interchange-cvs mailing list