[Petal] BUG: newlines within attributes?

Bruno Postle bruno at mkdoc.com
Fri Sep 9 17:10:47 BST 2005


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 %_)

-- 
Bruno
-------------- 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</', '');

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

</stuff>


More information about the Petal mailing list