[ic] Bug in "EITHER" coretag
Carl Bailey
carl at triangleresearch.com
Fri Mar 9 14:05:26 EST 2007
We found what we believe to be a fault in the [either] coretag.
We used the following code on a page:
[either][cgi idxnum][or]0[/either]
When the cgi value is absent this tag returns nothing -- a null string,
rather than the desired '0' character.
The reason for this is that the either coretag splits its body on
"[or]" and interpolates each chunk in turn, removes leading and
trailing spaces from the result and returns the first "true" result.
However in determining what to return, it uses the statement "return
$result if $result;" Obviously when $result = '0', this fails to
return anything. Further, it's not hard to picture a scenario where
NOT trimming space characters would be desired.
We therefore propose, for your consideration, the following replacement
to the tag, which adds a "notrim" option, and corrects the return
problem as well. We have used this tag successfully in our IC 5.2
environment:
UserTag either Order notrim
UserTag either hasEndTag
UserTag either PosNumber 0
UserTag either Version $Revision: 1.3.1 $
UserTag either Routine <<EOR
sub {
my ($notrim, $body) = @_;
my @ary = split /\[or\]/, $body;
my $result;
while(@ary) {
$result = interpolate_html(shift @ary);
unless ($notrim) {
$result =~ s/^\s+//;
$result =~ s/\s+$//;
}
return $result if length($result);
}
return;
}
EOR
Usage Example:
[seti delimiter][either notrim=1][scratch user_delim][or]
[/either][/seti]
Regards,
Carl Bailey
Triangle Research, Inc.
More information about the interchange-users
mailing list