Subject: | [PATCH] Don't map & to & when already in a valid entity construct |
Currently XML writer maps all instances of & to & which is great,
unless the & is already in an existing entity. This diff makes
XML::Writer leave existing entities alone.
--- Writer.pm.orig Sat Feb 25 22:27:21 2006
+++ Writer.pm Sat Feb 25 22:27:46 2006
@@ -342,7 +342,7 @@
my $characters = sub {
my $data = $_[0];
if ($data =~ /[\&\<\>]/) {
- $data =~ s/\&/\&\;/g;
+ $data =~ s/\&(?!(?:\w|#)+?\;)/\&\;/g;
$data =~ s/\</\<\;/g;
$data =~ s/\>/\>\;/g;
}
@@ -744,7 +744,7 @@
sub _escapeLiteral {
my $data = $_[0];
if ($data =~ /[\&\<\>\"]/) {
- $data =~ s/\&/\&\;/g;
+ $data =~ s/\&(?!(?:\w|#)+?\;)/\&\;/g;
$data =~ s/\</\<\;/g;
$data =~ s/\>/\>\;/g;
$data =~ s/\"/\"\;/g;