On 03/09/2007 03:17 PM, Stefan Hornburg (Racke) wrote:
> Peter wrote:
>>
>> On 03/09/2007 11:26 AM, Stefan Hornburg wrote:
>>> Carl Bailey wrote:
>>>> 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.
>>> Therefore the last statement in the tag should
be:
>>>
>>> return $result if $result =~ /S/;
>>
>> So what if the first result is "0"? it
would still return it.
>
> I said the last statement in the tag, not the return
within the loop.
>
>>
>> And I don't think this addresses the problem that
was originally stated
>> either.
>>
>> return $result if $result is the right way to do
it, but there needs to
>> be a way to return the last result in the loop if
all tests fail.
>
> See above.
Actually I think this may work best:
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 $result;
}
return $result;
}
There's no need to check the last return value, just return
it regardless.
Peter
_______________________________________________
interchange-users mailing list
interchange-users icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchan
ge-users
|