[Petal] [REQ] Escape HTML entities

Armin Helbach armin at syrius.de
Thu Oct 9 20:38:32 BST 2003


I think *now* I have worked out what to do to preserve the entities. I am sorry
for not sending diffs - I have messed around so much with your code and got no
time to reinstall an original version. sorry for that.

I changed 2 Files :

1. XML/Parser/Style/Stream.pm 
(I am sure one could also inherit the Stream.pm to some StreamandEntities.pm and
leave the XML::Parser Module untouched)
2. Petal/Parser/XMLWrapper.pm



1.) Add this sub somewhere in XML/Parser/Style/Stream.pm :

sub Default {
  my $expat = shift;
  #return entity literaly
  #only inside root element
  if ( $expat->element_index > 0 ) {
    $expat->{Text} .= shift;
  }
}


2.a) Add "NoExpand => 1" to Petal/Parser/XMLWrapper.pm :
sub process
{
    my $self = shift;
    local $Canonicalizer = shift;
    local @NameSpaces = ();

    my $data_ref = shift;
    $data_ref = (ref $data_ref) ? $data_ref : \$data_ref;
    my $parser = new XML::Parser (
        Style    => 'Stream',
        Pkg      => ref $self,
        ErrorContext => 2,
        NoExpand => 1,
       );

    $parser->parse ($$data_ref);
}

2.b) Prevent our nice Entities from beeing killed by Petal itself in
Petal/Parser/XMLWrapper.pm

sub Text
{
    local ($Petal::NS) = $NameSpaces[$#NameSpaces];
    local ($Petal::XI_NS) = $XI_NameSpaces[$#XI_NameSpaces];
   
    #s/\&/\&/g;
    
    s/\</\&lt\;/g;
    $Canonicalizer->Text();
}



Does this work for you?
Does this do what you want ?
Does this change something I did not notice at my quick tests?


Thanks for your help

armin who loves petal




More information about the Petal mailing list