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 |
Message body not shown because it is not plain text.
Subject: | test2 |
Message body not shown because it is not plain text.