[Petal] BUG: newlines within attributes?

Bruno Postle bruno at mkdoc.com
Sat Sep 10 21:22:21 BST 2005


On Fri 09-Sep-2005 at 18:13 +0100, Mark Holland wrote:
>
> I, and the guys doing Petal here, don't tend to split Petal attributes 
> across lines, so I'm sure it's something that could go unnoticed...

We have lots of stuff like this:

  <div petal:define="a string: ay;
                     b string: bee;
                     c string: cee;">

..but the Petal canonicaliser splits the attribute on the 
semi-colons and turns it into three separate statements, which then 
pass through the system happily.

The bug seems to be that the canonicaliser assumes that the 
code-generator can accept tags that span multiple lines.  Whereas 
the code-generator assumes that all canonicalised tags are on a 
single line.

Since I can think of no reason why we shouldn't allow newlines to 
pass through, this patch fixes the code-generator and is less 
intrusive than the previous one:

Index: lib/Petal/CodeGenerator.pm
===================================================================
RCS file: /var/spool/cvs/Petal/lib/Petal/CodeGenerator.pm,v
retrieving revision 1.46
diff -u -r1.46 CodeGenerator.pm
--- lib/Petal/CodeGenerator.pm  9 Jul 2004 11:09:34 -0000       1.46
+++ lib/Petal/CodeGenerator.pm  10 Sep 2005 20:06:10 -0000
@@ -162,9 +162,9 @@

     foreach $token (@{$tokens})
     {
-        if ($token =~ /$PI_RE/)
+        if ($token =~ /$PI_RE/s)
         {
-           ($token_name) = $token =~ /$PI_RE/;
+           ($token_name) = $token =~ /$PI_RE/s;
            my @atts1 = $token =~ /(\S+)\=\"(.*?)\"/gos;
            my @atts2 = $token =~ /(\S+)\=\'(.*?)\'/gos;
            %token_hash = (@atts1, @atts2);

-------------- next part --------------
#!/usr/bin/perl
use warnings;
use strict;
use lib ('lib');
use Test::More 'no_plan';
use Petal;

$Petal::BASE_DIR     = './t/data/';
$Petal::DISK_CACHE   = 0;
$Petal::MEMORY_CACHE = 0;
$Petal::TAINT        = 1;

my $string = Petal->new ('attribute-newline.xml')->process ();
like ($string, '/>apple</', '');
like ($string, '/>orange</', '');
like ($string, '/>plum</', '');
like ($string, '/>pear</', '');
like ($string, '/>ay bee cee</', '');
like ($string, '/>ex why zed</', '');

-------------- next part --------------
<stuff xmlns:petal="http://purl.org/petal/1.0/">

<div petal:define="foo
string: apple">$foo</div>
<div petal:define="bar string: orange">$bar</div>

<div petal:content="string:
plum">xxx</div>
<div petal:content="string: pear">xxx</div>

<div petal:define="
         a string: ay;
         b string: bee;
         c string: cee;
      "><span petal:replace="a" /> <span petal:replace="b" /> <span petal:replace="c" /></div>

<div petal:define="
         x
         string: ex;
         y string:
         why;
         z string: zed;
      "><span petal:replace="x" /> <span petal:replace="y" /> <span petal:replace="z" /></div>

</stuff>


More information about the Petal mailing list