Skip Menu |

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

Report information
The Basics
Id: 98801
Status: resolved
Priority: 0/
Queue: XML-Twig

People
Owner: Nobody in particular
Requestors: vkatsikaros [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 3.49



Subject: simplify behaves differently on empty element with and without CDATA
Date: Thu, 11 Sep 2014 19:14:10 +0300
To: bug-XML-Twig [...] rt.cpan.org
From: Vangelis Katsikaros <vkatsikaros [...] gmail.com>
Hi First, thanks for this great module! I encountered a difference in the behavior of XML::Twig->simplify when parsing empty elements with and without CDATA sections. ============================ Reproduce the bug ============================ When running the test script, with no options to simplify I get: perl test.pl $VAR1 = { 'foo' => 'something' }; $VAR1 = { 'foo' => '' }; $VAR1 = { 'foo' => 'something' }; $VAR1 = { 'foo' => undef }; but I was expecting perl test.pl $VAR1 = { 'foo' => 'something' }; $VAR1 = { 'foo' => undef }; $VAR1 = { 'foo' => 'something' }; $VAR1 = { 'foo' => undef }; or at least have the same behavior (either undef or '') when the element is empty both with and without CDATA . ============================ System details ============================ * verified with XML::Twig 3.48 (latest) and 3.32 * perl -v This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi * lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 10.04.4 LTS Release: 10.04 Codename: lucid * uname -a Linux xxxxx 2.6.32-41-server #94-Ubuntu SMP Fri Jul 6 18:15:07 UTC 2012 x86_64 GNU/Linux ============================ check perl code ============================ $ perl -c test.pl test.pl syntax OK $ perlcritic --stern test.pl test.pl source OK ============================ check xml file ============================ $ xmllint --noout test.xml $ xmllint --version xmllint: using libxml version 20706 Regards Vangelis Katsikaros PS consider the attached test perl script and xml file to be under the public domain. You can freely use, modify, and distribute them without any restrictions.

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

I checked the behaviour of XML::Simple's XMLin, which simplify tries its hardest to emulate, with empty elements. It turns out that in both cases (with and without the CDATA section, XMLin creates an empty hash for the element. So the output of test.pl should in fact be: $VAR1 = { 'foo' => 'something' }; $VAR1 = { 'foo' => {} }; $VAR1 = { 'foo' => 'something' }; $VAR1 = { 'foo' => {} }; Which is a bit of a pain since {} evaluates as true. But simplify is supposed to be 100% compatible with XMLin, so that's how I fixed it. Now the behaviour is at least consistent. Try the devlopment version at http://xmltwig.org/xmltwig/ and let me know if it works for you. -- mirod On Thu Sep 11 12:14:27 2014, vkatsikaros@gmail.com wrote: Show quoted text
> Hi > > First, thanks for this great module! > > I encountered a difference in the behavior of XML::Twig->simplify when > parsing empty elements with and without CDATA sections. > > ============================ > Reproduce the bug > ============================ > > When running the test script, with no options to simplify I get: > > perl test.pl > $VAR1 = { > 'foo' => 'something' > }; > $VAR1 = { > 'foo' => '' > }; > $VAR1 = { > 'foo' => 'something' > }; > $VAR1 = { > 'foo' => undef > }; > > but I was expecting > > perl test.pl > $VAR1 = { > 'foo' => 'something' > }; > $VAR1 = { > 'foo' => undef > }; > $VAR1 = { > 'foo' => 'something' > }; > $VAR1 = { > 'foo' => undef > }; > > or at least have the same behavior (either undef or '') when the > element is empty both with and without CDATA . > > > ============================ > System details > ============================ > > * verified with XML::Twig 3.48 (latest) and 3.32 > > * perl -v > This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi > > * lsb_release -a > No LSB modules are available. > Distributor ID: Ubuntu > Description: Ubuntu 10.04.4 LTS > Release: 10.04 > Codename: lucid > > * uname -a > Linux xxxxx 2.6.32-41-server #94-Ubuntu SMP Fri Jul 6 18:15:07 UTC 2012 > x86_64 GNU/Linux > > ============================ > check perl code > ============================ > > $ perl -c test.pl > test.pl syntax OK > $ perlcritic --stern test.pl > test.pl source OK > > ============================ > check xml file > ============================ > > $ xmllint --noout test.xml > $ xmllint --version > xmllint: using libxml version 20706 > > Regards > Vangelis Katsikaros > > PS consider the attached test perl script and xml file to be under the > public domain. You can freely use, modify, and distribute them without > any restrictions.
-- __ mirod