Subject: | Not allowed entities |
XML output is not parsed correctly when some not allowed entities are
used, for example "&something;"
To reproduce this problem try:
perl -MXML::Generator -le 'my $xg=XML::Generator->new(escape=>always);
print $xg->foo({bar=>"foo foo &bar; foo foo"}, "boo moo foo");'
<foo bar="foo foo &bar; foo foo">boo moo foo</foo>
perl -MXML::Simple -le 'XMLin( q{<foo bar="foo foo &bar; foo foo">boo
moo foo</foo>} )'
undefined entity at line 1, column 0, byte 0 at
/opt/perl-5.8.6/lib/site_perl/5.8.6/i686-linux-thread-multi/XML/Parser.pm
line 187
It occures in body part (<foo>&bar;</foo>) as well
It not includes entities like &#xxx;
My sugestion to fix this problem:
my %ENTITIES = ( # Entities allowed
quot => 1,
apos => 1,
lt => 1,
gt => 1,
amp => 1,
);
$_[0] =~ s/&(.+?);/ $ENTITIES{$1} && "#" ne substr($1, 0, 1)
? "&$1;"
: "&$1;"/ge;