Skip Menu |
 

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

Report information
The Basics
Id: 115333
Status: new
Priority: 0/
Queue: XML-Bare

People
Owner: Nobody in particular
Requestors: rmesser [...] intellisurvey.com
Cc:
AdminCc:

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



Subject: zero values are removed in obj2xml and save
Download (untitled) / with headers
text/plain 1.6k
If XML::Bare reads in something like <xml><v>0</v></xml> and then writes it back out, it gets changed to <xml><v /></xml>. This test fails on 0.53 and illustrates the issue: ---- use strict; use XML::Bare; use Test::More tests => 1; my $test_xml = '<xml><v>0</v></xml>'; my $obj = XML::Bare->new(text => $test_xml); my $root = $obj->parse; my $reverse_xml = XML::Bare::obj2xml( $root ); # strip newlines for a easy comparison $reverse_xml =~ s/\n//g; is($reverse_xml, $test_xml, 'obj2xml returns original xml'); ---- Here is the patch we are using that seems to resolve the issue: ---- index d10e595..2cfaacf 100755 --- a/lib/perl5/site_perl/5.22.1/x86_64-linux/XML/Bare.pm +++ b/lib/perl5/site_perl/5.22.1/x86_64-linux/XML/Bare.pm @@ -674,7 +674,7 @@ sub obj2xml { return $posa <=> $posb; } keys %$objs; for my $i ( @dex ) { - my $obj = $objs->{ $i } || ''; + my $obj = $objs->{ $i } // ''; my $type = ref( $obj ); if( $type eq 'ARRAY' ) { $imm = 0; @@ -721,7 +721,7 @@ sub obj2xml { my $cr = $imm ? '' : "\n"; if( substr( $name, 0, 1 ) ne '_' ) { if( $name ) { - if( $xml ) { + if( defined $xml ) { $xml = $pad . '<' . $name . $att . '>' . $cr . $xml . $pad2 . '</' . $name . '>'; } else { ---- This patch doesn't seem to cause any other problems, and the other tests in the XML::Bare test suite still pass after this change. So it would be nice to get this change approved by the author and merged into the code base because XML::Bare is a great option if you just want to read in xml to a data structure, change the data a bit, and then write it back out, but this bug can definitely bite you if that's how you are using the module.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.