Subject: | Priority values in exponential notation are rejected |
Date: | Thu, 12 Nov 2015 13:24:17 +0100 |
To: | bug-Heap-Priority [...] rt.cpan.org |
From: | Felix Kuehnl <felix [...] bioinf.uni-leipzig.de> |
Description:
There is a bug in the current version 0.11 of Heap::Priority that
prevents the insertion of items if its priority value is in exponential
notation (e.g. -2.75e-03) when converted to a string by Perl. As a
result, the following minimal example raises an exception:
perl -we '
use strict;
use Heap::Priority;
my $h=new Heap::Priority;
$h->raise_error(2);
$h->add("hey", -2.38418579101562e-07);
print $h->pop(), " end\n"; '
Expected result: The code should print "hey end" and exit.
Actual result: An exception is raised during the insertion.
Cause: The regular expression used to check the priority value validity,
i.e.
/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/
does not allow floating point values in exponential notation.
Fix: Extend the regex as follows:
/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?$/
Replace the lines of form
unless ($priority =~ /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/) {
by
unless ($priority =~
/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?$/) {
in the following functions / lines in Priority.pm:
- get_level:147:
- add:201:
- delete_item:(10th line):
- delete_priority_level:(7th line):
Or, probably better, introduce a global my variable
my $matchDecimal = qr/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?$/
to store the regex and replace the lines stated above by
unless ($priority =~ $matchDecimal) {
such that it can be maintained from a central point and duplication is
avoided.
Platform: I run Perl 5.18.4 on a 64-bit Fedora 21 Linux, kernel
4.1.8-100.fc21.x86_64.
As a side note, I think the error message on line 49 of Priority.pm (sub
raise_error()) should state that the 'error level' should be a whole
number, not the 'priority'. Please apply this patch to your package.
Thank you!
Regards,
Felix Kuehnl