[PERCEPS] {if first}/{if last} Bug found (and perhaps fixed)
Bernd Petrovitsch
bernd@gams.at
Mon, 28 May 2001 20:26:11 +0200
--==_Exmh_53299811P
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">
<title>Macros</title>
<variablelist>
{endif}
<varlistentry> =
<term>{type}</term>
<listitem>
<para>{args}</para>
<para>{brief}</para>
</listitem>
</varlistentry> =
{if last}
</variablelist>
</section>
{endif}
{next}
---- snip ----
to generate the list of all macros (or nothing if no macros are =
defined).
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
-- =
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
--==_Exmh_53299811P
Content-Type: application/pgp-signature
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: Exmh version 2.2 06/23/2000
iQBVAwUBOxKYQ6/rvrblD00BAQIbtQH/XJXKtzBKkuM/2zCCpL7TnQB+KCJ1aCal
acd0WJyKVBKTUgFT+EHkZRodAYhip4ZcAzaEItPcHq3o2Kb5Nc/5Ww==
=qQ3U
-----END PGP MESSAGE-----
--==_Exmh_53299811P--