[Petal] BUG: newlines within attributes?

Mark Holland mark at thinkfoo.com
Fri Sep 9 18:13:43 BST 2005


Hi Bruno,

I can confirm I get the bug with my unpatched version of Petal-2.16. The 
patch fixes it. I've also recompiled and tested our templates with the 
patched version and they seem fine.

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...

Cheers,
~mark

Bruno Postle wrote:

> It seems that Petal processes these two differently:
>
>  <div petal:content="string:
>    plum">xxx</div>
>
>  <div petal:content="string: pear">xxx</div>
>
> The first one gets 'half processed'.  I was under the impression that 
> Petal should be whitespace insensitive here.
>
> Attached a test case, Could somebody else confirm that I'm really 
> looking at such an obvious bug?
>
> The following one-liner fixes it for me.  Are there any valid reasons 
> for preserving newlines within attributes?
>
> Index: lib/Petal/Parser.pm
> ===================================================================
> RCS file: /var/spool/cvs/Petal/lib/Petal/Parser.pm,v
> retrieving revision 1.5
> diff -u -r1.5 Parser.pm
> --- lib/Petal/Parser.pm 9 Jul 2004 11:09:34 -0000       1.5
> +++ lib/Petal/Parser.pm 9 Sep 2005 16:07:22 -0000
> @@ -114,6 +114,8 @@
>     local %_ = %{shift()};
>     delete $_{'/'};
>
> +    foreach my $key (keys %_) { $_{$key} =~ s/\n/ /g }
> +
>     # process the Petal namespace
>     my $ns = (scalar @NameSpaces) ? $NameSpaces[$#NameSpaces] : 
> $Petal::NS;
>     foreach my $key (keys %_)
>
>------------------------------------------------------------------------
>
>#!/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</', '');
>
>  
>
>------------------------------------------------------------------------
>
><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>
>
></stuff>
>  
>



More information about the Petal mailing list