Skip Menu |

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

Report information
The Basics
Id: 69336
Status: resolved
Priority: 0/
Queue: XML-LibXML-Simple

People
Owner: Nobody in particular
Requestors: Matt.W.Johnson [...] morganstanley.com
Cc:
AdminCc:

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



Subject: ForceArray option too keen to set forcearray_always
Date: Thu, 7 Jul 2011 14:34:31 +0100
To: <bug-XML-LibXML-Simple [...] rt.cpan.org>
From: "Johnson, Matt W" <Matt.W.Johnson [...] morganstanley.com>
Hi, There is an option handling bug in XML::LibXML::Simple. If the "list of elements" type of ForceArray is used with exactly one element, the internal $opt{forcearray_always} is erroneously set. The bug affects all versions of XML::LibXML::Simple, up to and including 0.90. 159 my $fa = delete $opt{forcearray}; 160 my @fa = ref $fa eq 'ARRAY' ? @$fa : defined $fa ? $fa : (); 161 $opt{forcearray_always} = (@fa==1 && !ref $fa[0] && $fa[0]); Where $fa is either: undef or 0 (false) 1 (or otherwise scalar true) a reference to an array with at least 2 elements ...this code works correctly. However, if $fa is a reference to a singleton array: $opt{forcearray} = ['element']; 159 my $fa = ['element']; 160 my @fa = ('element'); 161 $opt{forcearray_always} = (1 && 1 && 1); 161 should check that the original $fa was not a reference, not $fa[0]. 161 $opt{forcearray_always} = (@fa==1 && !ref $fa && $fa[0]); Patch attached against 0.90. Matt Matt W. Johnson Morgan Stanley | Enterprise Infrastructure 25 Cabot Square | Canary Wharf | Floor 02 London, E14 4QA Phone: +44 20 7677-3487 Matt.W.Johnson@morganstanley.com -------------------------------------------------------------------------- NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or views contained herein are not intended to be, and do not constitute, advice within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and Consumer Protection Act. If you have received this communication in error, please destroy all electronic and paper copies and notify the sender immediately. Mistransmission is not intended to waive confidentiality or privilege. Morgan Stanley reserves the right, to the extent permitted under applicable law, to monitor electronic communications. This message is subject to terms available at the following link: http://www.morganstanley.com/disclaimers. If you cannot access these links, please notify us by reply message and we will send the contents to you. By messaging with Morgan Stanley you consent to the foregoing.

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

Subject: Re: [rt.cpan.org #69336] ForceArray option too keen to set forcearray_always
Date: Thu, 7 Jul 2011 17:59:29 +0200
To: "Johnson, Matt W via RT" <bug-XML-LibXML-Simple [...] rt.cpan.org>
From: Mark Overmeer <solutions [...] overmeer.net>
* Johnson, Matt W via RT (bug-XML-LibXML-Simple@rt.cpan.org) [110707 13:34]: Show quoted text
> There is an option handling bug in XML::LibXML::Simple.
It's a bug alright, but not the correct fix. There are a few weird cases with this option. Probably, the line should be - $opt{forcearray_always} = (@fa==1 && !ref $fa[0] && $fa[0]); + $opt{forcearray_always} = @fa==1 && $fa[0] eq 1; It's quite nasty, because their may be a qr// -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Subject: RE: [rt.cpan.org #69336] ForceArray option too keen to set forcearray_always
Date: Thu, 7 Jul 2011 17:07:54 +0100
To: <bug-XML-LibXML-Simple [...] rt.cpan.org>
From: "Johnson, Matt W" <Matt.W.Johnson [...] morganstanley.com>
Well, indeed, (ref(qr//) eq 'Regexp'), but surely the only case for $opt{forcearray_always} to be set is where $fa (i.e. the original $opt{forcearray}) is not a reference (i.e. not a regexp, nor an arrayref) and that $fa is true? (I'm not quite sure why (!ref $fa) is unsafe in this circumstance.) I've patched around the problem for now, but an updated release with a fix would be very much appreciated. Thanks Matt Show quoted text
> -----Original Message----- > From: Mark Overmeer via RT [mailto:bug-XML-LibXML-Simple@rt.cpan.org] > Sent: 07 July 2011 17:00 > To: Johnson, Matt W (Enterprise Infrastructure) > Subject: Re: [rt.cpan.org #69336] ForceArray option too keen to set > forcearray_always > > <URL: https://rt.cpan.org/Ticket/Display.html?id=69336 > > > * Johnson, Matt W via RT (bug-XML-LibXML-Simple@rt.cpan.org) [110707 > 13:34]:
> > There is an option handling bug in XML::LibXML::Simple.
> > It's a bug alright, but not the correct fix. There are a few weird > cases with this option. Probably, the line should be > > - $opt{forcearray_always} = (@fa==1 && !ref $fa[0] && $fa[0]); > + $opt{forcearray_always} = @fa==1 && $fa[0] eq 1; > > It's quite nasty, because their may be a qr// > -- > Regards, > MarkOv > > ----------------------------------------------------------------------- > - > Mark Overmeer MSc MARKOV > Solutions > Mark@Overmeer.net > solutions@overmeer.net > http://Mark.Overmeer.net > http://solutions.overmeer.net >
-------------------------------------------------------------------------- NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or views contained herein are not intended to be, and do not constitute, advice within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and Consumer Protection Act. If you have received this communication in error, please destroy all electronic and paper copies and notify the sender immediately. Mistransmission is not intended to waive confidentiality or privilege. Morgan Stanley reserves the right, to the extent permitted under applicable law, to monitor electronic communications. This message is subject to terms available at the following link: http://www.morganstanley.com/disclaimers. If you cannot access these links, please notify us by reply message and we will send the contents to you. By messaging with Morgan Stanley you consent to the foregoing.
Subject: Re: [rt.cpan.org #69336] ForceArray option too keen to set forcearray_always
Date: Fri, 8 Jul 2011 10:46:35 +0200
To: "Johnson, Matt W via RT" <bug-XML-LibXML-Simple [...] rt.cpan.org>
From: Mark Overmeer <solutions [...] overmeer.net>
* Johnson, Matt W via RT (bug-XML-LibXML-Simple@rt.cpan.org) [110707 16:08]: Show quoted text
> I've patched around the problem for now, but an updated release with > a fix would be very much appreciated.
I rewrote it again: my $fa = delete $opt{forcearray} || 0; my (@fa_regex, %fa_elem); if(ref $fa) { foreach (ref $fa eq 'ARRAY' ? @$fa : $fa) { if(ref $_ eq 'Regexp') { push @fa_regex, $_ } else { $fa_elem{$_} = 1 } } } else { $opt{forcearray_always} = $fa } $opt{forcearray_regex} = \@fa_regex; $opt{forcearray_elem} = \%fa_elem; Hopefully easier to read. Can you give it a try? Then I will release a fixed version today. -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Subject: RE: [rt.cpan.org #69336] ForceArray option too keen to set forcearray_always
Date: Fri, 8 Jul 2011 10:05:18 +0100
To: <bug-XML-LibXML-Simple [...] rt.cpan.org>
From: "Johnson, Matt W" <Matt.W.Johnson [...] morganstanley.com>
Not easy for me to try here directly, but by inspection it looks like the code does indeed do the right thing! Thanks Matt Show quoted text
> -----Original Message----- > From: Mark Overmeer via RT [mailto:bug-XML-LibXML-Simple@rt.cpan.org] > Sent: 08 July 2011 09:47 > To: Johnson, Matt W (Enterprise Infrastructure) > Subject: Re: [rt.cpan.org #69336] ForceArray option too keen to set > forcearray_always > > <URL: https://rt.cpan.org/Ticket/Display.html?id=69336 > > > * Johnson, Matt W via RT (bug-XML-LibXML-Simple@rt.cpan.org) [110707 > 16:08]:
> > I've patched around the problem for now, but an updated release with > > a fix would be very much appreciated.
> > I rewrote it again: > > my $fa = delete $opt{forcearray} || 0; > my (@fa_regex, %fa_elem); > if(ref $fa) > { foreach (ref $fa eq 'ARRAY' ? @$fa : $fa) > { if(ref $_ eq 'Regexp') { push @fa_regex, $_ } > else { $fa_elem{$_} = 1 } > } > } > else { $opt{forcearray_always} = $fa } > $opt{forcearray_regex} = \@fa_regex; > $opt{forcearray_elem} = \%fa_elem; > > Hopefully easier to read. > Can you give it a try? Then I will release a fixed version today. > -- > Regards, > > MarkOv > > ----------------------------------------------------------------------- > - > Mark Overmeer MSc MARKOV > Solutions > Mark@Overmeer.net > solutions@overmeer.net > http://Mark.Overmeer.net > http://solutions.overmeer.net >
-------------------------------------------------------------------------- NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or views contained herein are not intended to be, and do not constitute, advice within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and Consumer Protection Act. If you have received this communication in error, please destroy all electronic and paper copies and notify the sender immediately. Mistransmission is not intended to waive confidentiality or privilege. Morgan Stanley reserves the right, to the extent permitted under applicable law, to monitor electronic communications. This message is subject to terms available at the following link: http://www.morganstanley.com/disclaimers. If you cannot access these links, please notify us by reply message and we will send the contents to you. By messaging with Morgan Stanley you consent to the foregoing.
fixed in 0.91, released jul 2011