Subject: | Twig causes panic when processing what appears to be a sane file. |
Date: | Thu, 9 Aug 2012 22:49:54 +0000 |
To: | "bug-XML-Twig [...] rt.cpan.org" <bug-XML-Twig [...] rt.cpan.org> |
From: | Eric Ellis <eellis [...] classroom24-7.com> |
I'm not sure this is a Twig bug, but I'm at a loss as to what causes this, and it appears to be Twig related.
I've attached the file in question. It's a job file for Microsoft Expression Encoder that happens to be XML an XML file with a different name.
I can reliably cause a perl crash (currently using ActivePerl 5.12.4 on Win7 64, using Twig 3.39 from the AS repo) with this code and the attached file:
<code>
use warnings;
use strict;
use XML::Twig;
my $twig = new XML::Twig(pretty_print => 'indented');
open(
my $job_file,
"<:encoding(utf8)",
$ARGV[0]
);
eval { $twig->safe_parse($job_file); };
my $metadata = $twig->first_elt('Metadata');
my @items = $metadata->children();
foreach my $i (@items) { print $i->att_names; }
</code>
Removing encoding appears to sidestep it nicely, but the file appears to be encoded UTF8. If I open with safe_parsefile, it behaves as expected as well.
I can print the file with no issues when opened with the encoding stanza.
Thanks for your time and effort Michael. Twig's been in use in my internal software for the last couple of years. I shudder to think about having to use any of the other less useable tools for XML manipulation.
--
Eric Ellis
eellis@classroom24-7.com
http://www.classroom24-7.com
Message body not shown because it is not plain text.