Skip Menu |

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

Report information
The Basics
Id: 3711
Status: resolved
Worked: 1 hour (60 min)
Priority: 0/
Queue: XML-Twig

Owner: Nobody in particular
Requestors: sf [...]

Bug Information
Severity: Important
Broken in: 3.10
Fixed in: 3.11


Subject: Comments always dropped after a twig object set 'comments' to 'drop'
Download (untitled) / with headers
text/plain 1.3k
Hi, I've noticed that if you create an XML::Twig object with 'comments' set to 'drop', then all subsequent XML::Twig objects also drop comments, even if they have set 'comments' to 'keep'. It looks like this is because the code deletes the twig handler. Below is a small test script to demonstrate the problem. I've attached a diff against that ships with version 3.10 that fixes this problem. Thanks for this great module. Simon Flack #!/usr/local/bin/perl -w use strict; use XML::Twig; use Test::Simple tests => 3; my $xml = <<XML_TEST; <xml_root> <!-- some comment --> <key>value</key> </xml_root> XML_TEST { my $twig1 = XML::Twig->new(comments => 'keep', keep_spaces => 1); $twig1->parse($xml); ok ($twig1->sprint() =~ /<!--.*-->/s, 'keep comments'); #print $twig1->sprint, "\n", '-'x80, "\n"; # keeps comments ok $twig1->dispose; } { my $twig2 = XML::Twig->new(comments => 'drop', keep_spaces => 1); $twig2->parse($xml); ok ($twig2->sprint() !~ /<!--.*-->/s, 'drop comments'); #print $twig2->sprint, "\n", '-'x80, "\n"; # drops comments ok $twig2->dispose; } { my $twig3 = XML::Twig->new(comments => 'keep', keep_spaces => 1); $twig3->parse($xml); ok ($twig3->sprint() =~ /<!--.*-->/s, 'keep comments'); #print $twig3->sprint, "\n", '-'x80, "\n"; # drops comments!! $twig3->dispose; }
--- Sun Jun 8 23:01:16 2003 +++ Wed Sep 3 18:26:00 2003 @@ -464,5 +464,5 @@ $args{Comments}||= $COMMENTS_DEFAULT; if( $args{Comments} eq 'drop') - { delete $twig_handlers{Comment}; } + { $self->{twig_keep_comments}= 0; } elsif( $args{Comments} eq 'keep') { $self->{twig_keep_comments}= 1; } @@ -1731,4 +1731,5 @@ my( $p, $data)= @_; my $t=$p->{twig}; + return unless $t->{twig_keep_comments}; $data= $t->{twig_input_filter}->( $data) if( $t->{twig_input_filter});
Download (untitled) / with headers
text/plain 258b
Thanks, Indeed there was a bug. Thanks for the fix too. After adding a test for the case where the comments are treated as full nodes ('process') all tests pass, including the one you sent. The fix is in version 3.11 at __ Mirod

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

Please report any issues with to