Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: kahn [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 3.32
Fixed in: 3.33



Subject: XML::Twig::Elt->set_content fails when argument is 'XML::Twig::Elt'
The XML::Twig::Elt->set_content() method checks whether its argument is already an element by testing whether (isa( $_[0], 'XML::Twig::Elt')) . Unfortunately, if $_[0] is the actual string 'XML::Twig::Elt' (or the exact name of some subclass of XML::Twig::Elt, which is how I discovered it [subclass 'Line', oops]), then many of the internal assumptions are violated and XML::Parser will crash deeper in. I have attached two files: * a new test case that replicates the bug * a patch for the bug (I named it test_3_33; feel free to rename of course). Please patch and release soon so I can use the distribution version of this code again (rather than my own patches!). --Jeremy
Subject: xml-twig-ref-error-crasher.patch
Only in XML-Twig-3.33-jgk/t: test_3_33.t diff --unified --recursive XML-Twig-3.33/Twig.pm XML-Twig-3.33-jgk/Twig.pm --- XML-Twig-3.33/Twig.pm 2008-10-26 16:45:40.000000000 -1000 +++ XML-Twig-3.33-jgk/Twig.pm 2008-10-26 16:53:49.000000000 -1000 @@ -8341,7 +8341,7 @@ { $child->delete; } foreach my $child (@_) - { if( isa( $child, 'XML::Twig::Elt')) + { if( ref $child and isa( $child, 'XML::Twig::Elt')) { # argument is an element $child->paste( 'last_child', $elt); } diff --unified --recursive XML-Twig-3.33/Twig_pm.slow XML-Twig-3.33-jgk/Twig_pm.slow --- XML-Twig-3.33/Twig_pm.slow 2008-10-14 00:45:01.000000000 -1000 +++ XML-Twig-3.33-jgk/Twig_pm.slow 2008-10-26 16:53:30.000000000 -1000 @@ -8344,7 +8344,7 @@ { $child->delete; } foreach my $child (@_) - { if( isa( $child, 'XML::Twig::Elt')) + { if( ref $child and isa( $child, 'XML::Twig::Elt')) { # argument is an element $child->paste( 'last_child', $elt); } Only in XML-Twig-3.33-jgk/: Twig_pm.slow~
Subject: test_3_33.t
#!/usr/bin/perl -w use strict; # $Id: /xmltwig/trunk/t/test_3_30.t 27 2007-08-30T08:07:25.079327Z mrodrigu $ use strict; use Carp; use File::Spec; use lib File::Spec->catdir(File::Spec->curdir,"t"); use tools; $|=1; my $DEBUG=0; use XML::Twig; my $TMAX=1; print "1..$TMAX\n"; my $tok = XML::Twig::Elt->new(foo => {} => 'XML::Twig::Elt'); ok (defined $tok and $tok->isa('XML::Twig::Elt'), 'created an token with classname in text element'); exit 0; 1;
Subject: Re: [rt.cpan.org #40399] XML::Twig::Elt->set_content fails when argument is 'XML::Twig::Elt'
Date: Wed, 29 Oct 2008 11:15:58 +0100
To: bug-XML-Twig [...] rt.cpan.org
From: mirod <xmltwig [...] gmail.com>
Jeremy Kahn via RT wrote: Show quoted text
> Sun Oct 26 23:09:12 2008: Request 40399 was acted upon. > Transaction: Ticket created by KAHN > Queue: XML-Twig > Subject: XML::Twig::Elt->set_content fails when argument is 'XML::Twig::Elt' > Broken in: 3.32 > Severity: Important > Owner: Nobody > Requestors: kahn@cpan.org > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=40399 > > > > The XML::Twig::Elt->set_content() method checks whether its argument is > already an element by testing whether (isa( $_[0], 'XML::Twig::Elt')) . > > Unfortunately, if $_[0] is the actual string 'XML::Twig::Elt' (or the > exact name of some subclass of XML::Twig::Elt, which is how I discovered > it [subclass 'Line', oops]), then many of the internal assumptions are > violated and XML::Parser will crash deeper in. > > I have attached two files: > * a new test case that replicates the bug > * a patch for the bug (I named it test_3_33; feel free to rename of course). > > Please patch and release soon so I can use the distribution version of > this code again (rather than my own patches!).
Thanks, nice catch, I had forgotten that UNIVERSAL::Isa can take a string as the first argument. It's done on the development version on my site. I have a couple more bugs to fix before being able te do a release, I'll try to work on them as soon as I can. -- mirod
Subject: Re: [rt.cpan.org #40399] XML::Twig::Elt->set_content fails when argument is 'XML::Twig::Elt'
Date: Wed, 29 Oct 2008 09:53:57 -0700
To: bug-XML-Twig [...] rt.cpan.org
From: "Jeremy G. Kahn" <kahn [...] cpan.org>
xmltwig@gmail.com via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=40399 > > > Jeremy Kahn via RT wrote: >
>> Sun Oct 26 23:09:12 2008: Request 40399 was acted upon. >> Transaction: Ticket created by KAHN >> Queue: XML-Twig >> Subject: XML::Twig::Elt->set_content fails when argument is 'XML::Twig::Elt' >> Broken in: 3.32 >> Severity: Important >> Owner: Nobody >> Requestors: kahn@cpan.org >> Status: new >> Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=40399 > >> >> >> The XML::Twig::Elt->set_content() method checks whether its argument is >> already an element by testing whether (isa( $_[0], 'XML::Twig::Elt')) . >> >> Unfortunately, if $_[0] is the actual string 'XML::Twig::Elt' (or the >> exact name of some subclass of XML::Twig::Elt, which is how I discovered >> it [subclass 'Line', oops]), then many of the internal assumptions are >> violated and XML::Parser will crash deeper in. >> >> I have attached two files: >> * a new test case that replicates the bug >> * a patch for the bug (I named it test_3_33; feel free to rename of course). >> >> Please patch and release soon so I can use the distribution version of >> this code again (rather than my own patches!). >>
> > Thanks, nice catch, I had forgotten that UNIVERSAL::Isa can take a string as the > first argument. > > It's done on the development version on my site. > > I have a couple more bugs to fix before being able te do a release, I'll try to > work on them as soon as I can. >
IMO this behavior by UNIVERSAL::isa is-a bug, because the way you're using it is sane. but fixing the behavior would break too much, and asking for a new UNIVERSAL method is kind of a tall order. There are many other uses of raw isa() in the code -- have you confirmed that they're all applying to non-strings? I haven't because I don't know how to exercise enough chunks of the code to write test cases. I appreciate your quick response -- I have bugs on other modules I've filed that sit idle for weeks or months (and, of course, some of the packages are abandoned). And a few bugs against my own packages have gone unresponded to for a long time. I must follow your example. --Jeremy
Subject: Re: [rt.cpan.org #40399] XML::Twig::Elt->set_content fails when argument is 'XML::Twig::Elt'
Date: Wed, 29 Oct 2008 18:29:14 +0100
To: bug-XML-Twig [...] rt.cpan.org
From: mirod <xmltwig [...] gmail.com>
Jeremy Kahn via RT wrote: Show quoted text
> Queue: XML-Twig > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=40399 >
Show quoted text
> IMO this behavior by UNIVERSAL::isa is-a bug, because the way you're > using it is sane. but fixing the behavior would break too much, and > asking for a new UNIVERSAL method is kind of a tall order. There are > many other uses of raw isa() in the code -- have you confirmed that > they're all applying to non-strings? I haven't because I don't know how > to exercise enough chunks of the code to write test cases.
It works the same way inheritance works in Perl, so it makes sense. It's just a pain to have to write if( ref( $foo) && isa( $foo, 'class')), because of course it's often used as a sub instead of a method. I have added the test on ref( $obj) in a few places, where it made sense. I have yet to add the tests though. Show quoted text
> I appreciate your quick response -- I have bugs on other modules I've > filed that sit idle for weeks or months (and, of course, some of the > packages are abandoned). And a few bugs against my own packages have > gone unresponded to for a long time. I must follow your example.
I am usually OK when responding to bug reports, but I tend to delay releases way too much, as there seems to always be "one more bug" that needs fixing... Thanks -- mirod