Subject: | attributes containing quote character don't escape properly |
As far as I understand the behavior, doing something like:
$elt = XML::Twig::Elt->new('baz');
$elt->set_att(foo => '"');
print $elt->sprint();
is perfectly legal. However, this prints something like this:
<baz foo="""/>
which is illegal XML; XML::Parser barfs on reading this back in.
I dug through the code, and as far as I can tell in version 3.33 this is
still a problem -- it's because the escapes for replacing things in
attribute values don't include the (variable) quote symbol.
Luckily, it seems to be a one-line patch to adjust the
$replace_in_att_value symbol properly:
Patch in Twig.pm (well, Twig_pm.slow in the distribution).
+++ Twig_pm.slow~ 2009-08-11 08:06:11.000000000 -0700
@@ -7546,11 +7546,11 @@
my $att_sep = $pretty==$NSGMLS ? "\n"
--
;
- my $replace_in_att_value= $replaced_ents . $quote;
+ my $replace_in_att_value= $replaced_ents;
if( $option->{escape_gt} && $replaced_ents !~ m{>}) {
$replace_in_att_value.= '>'; }
my $tag;
my @att_names= grep { !_is_private_name( $_) } $keep_atts_order ?
keys %{$att} : sort keys %{$att};
if( @att_names)