[PERCEPS] {if first}/{if last} Bug found (and perhaps fixed)

Bernd Petrovitsch bernd@gams.at
Mon, 28 May 2001 20:26:11 +0200

Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Hi all !

I just discovered a (serious) bug in perceps-3.5.0 :
My template files produce DocBook-sgml output, so the syntax =

requirements are quite strict.
I use e.g.
----  snip  ----
{foreach macro sort}
{if first }
<section id=3D"macros">
		<varlistentry>	=

		</varlistentry>	=

{if last}
----  snip  ----
to generate the list of all macros (or nothing if no macros are =

Now the bug is if there is exactly on element in the list. In this =

case the {if first} ... {endif} is ignored.
Looking in the source (around line 1043), there is the sequence
----  snip  ----
              (($arg[1] eq "first") && $ord=3D=3D0)  ||
              (($arg[1] eq "last") && $ord=3D=3D-1)  ||
----  snip  ----
which shows the problem. In case of a one-element list $ord always =3D=3D=

-1 (which basically is correct).
I attached a patch which fixes two problems:
-) I added ".sgml" similar to ".html" wrt escaping of < and >.
-) I fixed above bug quite crude : Instead of -1 in the last iteration
   -$index (i.e.  -$#group). So I have "-0" if there is exacly one =

   element in the list and "0" (on the first iteration) if there are =

   more than one element. Don't ask me if this behaviour is actually =

   defined by perl or not.

-- =

Bernd Petrovitsch                              Email : bernd@gams.at
g.a.m.s gmbh                                  Fax : +43 1 205255-900
Prinz-Eugen-Stra=DFe 8                    A-1040 Vienna/Austria/Europe
                     LUGA : http://www.luga.at

Content-Type: application/pgp-signature

Version: GnuPG v1.0.4 (GNU/Linux)
Comment: Exmh version 2.2 06/23/2000