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.