Skip Menu |

This queue is for tickets about the XML-XML2JSON CPAN distribution.

Report information
The Basics
Id: 94335
Status: open
Priority: 0/
Queue: XML-XML2JSON

People
Owner: Nobody in particular
Requestors: perl [...] minty.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.06
Fixed in: (no value)



Subject: obj2dom intermittent failure
I believe I've found a bug that is intermittent or "random" and is triggered based on how a Perl hashref is ordered -- something that isn't guaranteed. Hence the random failures. In short: the code is using "keys %hash", and depending on which key is returned first, the installation tests for XML::XML2JSON may fail or pass. I've seen this problem on a vanilla Ubunutu 12.04 and also the latest 14.04 beta. I'm using perlenv and the problem persists on multiple recent Perls. § uname -a Linux reg-gold-20140328 3.13.0-19-generic #40-Ubuntu SMP Mon Mar 24 02:37:00 UTC 2014 i686 i686 i686 GNU/Linux § perl -v This is perl 5, version 19, subversion 10 (v5.19.10) built for i686-linux Running: prove ./test1 will sometimes pass, sometimes fail. Just keep running it a few times. Either all the XML2JSON tests pass, or they all fail. The error comes from: lib/XML/XML2JSON.pm (around line 760) sub obj2dom eval { $Root = $Dom->createElement($Name) }; And is either: Problem creating root element @version: bad name or Problem creating root element @encoding: bad name When using the following json from the tests '{"@version":"1.0","test":{"data":{"@attr1":"test","$t":"some test text"},"test$nstest":{"@attr1":"bar"},"@xmlns:test":"http://test.example/test","censored":{},"array":{"@perl":"awesome","item":[{"@index":"0"},{"@index":"1"},{"@index":"2"}]},"empty":{"inner":{"@c":"d"}}},"@encoding":"UTF-8"}' Note that we have three top level keys here: @version @encoding test And that the obj2dom sub iterates on these using: foreach my $Key ( keys %$Obj ) If the first key is 'test', then things work. If the first key is either @version or @encoding, then XML2JSON->obj2dom tries to construct a root level node using those as the name, and this fails. Essentially: # works eval { $Root = $Dom->createElement('test') }; # fails eval { $Root = $Dom->createElement('@version') }; See attached 'test2' for a much simpler demostration of this problem. I'm not clear what the correct behaviour is here when trying to construct a dom with a root node with a name starting with '@'. Regardless, the fact that the installation tests for this module "randomly" pass or fail based on the undefined ordering of the keys in a %hash seems like a bug.
Subject: test1
Download test1
application/octet-stream 720b

Message body not shown because it is not plain text.

Subject: test2
Download test2
application/octet-stream 388b

Message body not shown because it is not plain text.

From: rrt [...] sc3d.org
On Mon Mar 31 08:21:59 2014, perl@minty.org wrote: Show quoted text
> I believe I've found a bug that is intermittent or "random" and is > triggered based on how a Perl hashref is ordered -- something that > isn't guaranteed. Hence the random failures.
I get an identical random failure while running "cpan XML::XML2JSON".
There seems to be two "solutions" that both work. One is to un-comment the line before the foreach, which removes all attributes before iterating, but I assume there is a reason why it is there. The other is to do `reverse sort keys` instead of just `keys`. This ensures attributes sort last, so any root elements that need to be made are made before we get to the attributes
RT-Send-CC: rrt [...] sc3d.org
On 2014-03-31 08:21:59, perl@minty.org wrote: Show quoted text
> I believe I've found a bug that is intermittent or "random" and is > triggered based on how a Perl hashref is ordered -- something that > isn't guaranteed. Hence the random failures. > > In short: the code is using "keys %hash", and depending on which key > is returned first, the installation tests for XML::XML2JSON may fail > or pass. > > I've seen this problem on a vanilla Ubunutu 12.04 and also the latest > 14.04 beta. I'm using perlenv and the problem persists on multiple > recent Perls. > > § uname -a > Linux reg-gold-20140328 3.13.0-19-generic #40-Ubuntu SMP Mon Mar 24 > 02:37:00 UTC 2014 i686 i686 i686 GNU/Linux > > § perl -v > > This is perl 5, version 19, subversion 10 (v5.19.10) built for i686- > linux > > Running: > > prove ./test1 > > will sometimes pass, sometimes fail. > > Just keep running it a few times. Either all the XML2JSON tests pass, > or they all fail. > > The error comes from: > > lib/XML/XML2JSON.pm (around line 760) > sub obj2dom > eval { $Root = $Dom->createElement($Name) }; > > And is either: > > Problem creating root element @version: bad name > > or > > Problem creating root element @encoding: bad name > > When using the following json from the tests > > '{"@version":"1.0","test":{"data":{"@attr1":"test","$t":"some test > text"},"test$nstest":{"@attr1":"bar"},"@xmlns:test":"http://test.example/test","censored":{},"array":{"@perl":"awesome","item":[{"@index":"0"},{"@index":"1"},{"@index":"2"}]},"empty":{"inner":{"@c":"d"}}},"@encoding":"UTF- > 8"}' > > Note that we have three top level keys here: > > @version > @encoding > test > > And that the obj2dom sub iterates on these using: > > foreach my $Key ( keys %$Obj ) > > If the first key is 'test', then things work. If the first key is > either @version or @encoding, then XML2JSON->obj2dom tries to > construct a root level node using those as the name, and this fails. > > Essentially: > > # works > eval { $Root = $Dom->createElement('test') }; > > # fails > eval { $Root = $Dom->createElement('@version') }; > > See attached 'test2' for a much simpler demostration of this problem. > > I'm not clear what the correct behaviour is here when trying to > construct a dom with a root node with a name starting with '@'. > > Regardless, the fact that the installation tests for this module > "randomly" pass or fail based on the undefined ordering of the keys in > a %hash seems like a bug.
The CPAN module Bio::Phylo is also affected: https://github.com/rvosa/bio-phylo/issues/31