Subject: | Unicode digit fail in Number::Fraction |
Date: | Mon, 15 Jun 2009 16:44:22 +0100 |
To: | bug-Number-Fraction [...] rt.cpan.org |
From: | Zefram <zefram [...] fysh.org> |
If Number::Fraction gets input consisting of non-ASCII Unicode digits,
it accepts it as valid, but then falls over due to failure of numeric
conversion:
$ perl -MNumber::Fraction -lwe \
'print Number::Fraction->new("\x{666}") // "nan"'
Argument "\x{666}" isn't numeric in numeric gt (>) at /usr/local/share/perl/5.10.0/Number/Fraction.pm line 374.
Illegal modulus zero at /usr/local/share/perl/5.10.0/Number/Fraction.pm line 379.
By contrast, a non-digit Unicode character is correctly rejected:
$ perl -MNumber::Fraction -lwe \
'print Number::Fraction->new("\x{555}") // "nan"'
nan
and an ASCII digit works correctly:
$ perl -MNumber::Fraction -lwe \
'print Number::Fraction->new("6") // "nan"'
6
The source of the bug is that the code uses /\d/ where it really wants
/[0-9]/.
There's also a similar bug, producing less spectacular failures, due to
using /$/ where it really wants /\z/. This causes input such as "6\n"
to be accepted, whereas "6\n\n" is correctly rejected.
-zefram