From bf86903d387f0b7668483583d1b1b9883559e8d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Wed, 11 Jan 2017 09:24:21 +0100
Subject: [PATCH] Ignore leading and trailing white spaces for non-decimal
input
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Documentation reads that surrounding white space is ignored. But this
does not work for non-decimal numbers since Math-BigInt-1.999712:
$ perl -MMath::BigInt -e 'print Math::BigInt->new(" 0x1 "), qq{\n}'
NaN
This patch fixes it.
<
https://bugzilla.redhat.com/show_bug.cgi?id=1412052>
Signed-off-by: Petr PÃsaÅ <ppisar@redhat.com>
---
lib/Math/BigFloat.pm | 6 ++++++
lib/Math/BigInt.pm | 6 ++++++
t/from_bin-mbf.t | 4 +++-
t/from_bin-mbi.t | 4 +++-
t/from_hex-mbf.t | 4 +++-
t/from_hex-mbi.t | 4 +++-
t/from_oct-mbf.t | 4 +++-
t/from_oct-mbi.t | 4 +++-
8 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/lib/Math/BigFloat.pm b/lib/Math/BigFloat.pm
index 18780b4..98f19d8 100644
--- a/lib/Math/BigFloat.pm
+++ b/lib/Math/BigFloat.pm
@@ -529,6 +529,7 @@ sub from_hex {
if ($str =~ s/
^
+ \s*
# sign
( [+-]? )
@@ -555,6 +556,7 @@ sub from_hex {
( \d+ (?: _ \d+ )* )
)?
+ \s*
$
//x)
{
@@ -618,6 +620,7 @@ sub from_oct {
if ($str =~ s/
^
+ \s*
# sign
( [+-]? )
@@ -641,6 +644,7 @@ sub from_oct {
( \d+ (?: _ \d+ )* )
)?
+ \s*
$
//x)
{
@@ -704,6 +708,7 @@ sub from_bin {
if ($str =~ s/
^
+ \s*
# sign
( [+-]? )
@@ -730,6 +735,7 @@ sub from_bin {
( \d+ (?: _ \d+ )* )
)?
+ \s*
$
//x)
{
diff --git a/lib/Math/BigInt.pm b/lib/Math/BigInt.pm
index da9075d..a6508ea 100644
--- a/lib/Math/BigInt.pm
+++ b/lib/Math/BigInt.pm
@@ -731,12 +731,14 @@ sub from_hex {
if ($str =~ s/
^
+ \s*
( [+-]? )
(0?x)?
(
[0-9a-fA-F]*
( _ [0-9a-fA-F]+ )*
)
+ \s*
$
//x)
{
@@ -785,11 +787,13 @@ sub from_oct {
if ($str =~ s/
^
+ \s*
( [+-]? )
(
[0-7]*
( _ [0-7]+ )*
)
+ \s*
$
//x)
{
@@ -838,12 +842,14 @@ sub from_bin {
if ($str =~ s/
^
+ \s*
( [+-]? )
(0?b)?
(
[01]*
( _ [01]+ )*
)
+ \s*
$
//x)
{
diff --git a/t/from_bin-mbf.t b/t/from_bin-mbf.t
index e24cd3b..893662d 100644
--- a/t/from_bin-mbf.t
+++ b/t/from_bin-mbf.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 183;
+use Test::More tests => 190;
my $class;
@@ -88,3 +88,5 @@ NaN:NaN
+inf:NaN
-inf:NaN
0b.p+0:NaN
+
+ 0b1 :1
diff --git a/t/from_bin-mbi.t b/t/from_bin-mbi.t
index b33eb67..b83d87d 100644
--- a/t/from_bin-mbi.t
+++ b/t/from_bin-mbi.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 344;
+use Test::More tests => 351;
my $class;
@@ -114,3 +114,5 @@ __END__
NaN:NaN
+inf:NaN
-inf:NaN
+
+ 0b1 :1
diff --git a/t/from_hex-mbf.t b/t/from_hex-mbf.t
index 1a39949..000b2ab 100644
--- a/t/from_hex-mbf.t
+++ b/t/from_hex-mbf.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 183;
+use Test::More tests => 190;
my $class;
@@ -88,3 +88,5 @@ NaN:NaN
+inf:NaN
-inf:NaN
0x.p+0:NaN
+
+ 0x1 :1
diff --git a/t/from_hex-mbi.t b/t/from_hex-mbi.t
index 2bb1301..a4c6227 100644
--- a/t/from_hex-mbi.t
+++ b/t/from_hex-mbi.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 344;
+use Test::More tests => 351;
my $class;
@@ -114,3 +114,5 @@ __END__
NaN:NaN
+inf:NaN
-inf:NaN
+
+ 0x1 :1
diff --git a/t/from_oct-mbf.t b/t/from_oct-mbf.t
index b735bd5..d59c33c 100644
--- a/t/from_oct-mbf.t
+++ b/t/from_oct-mbf.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 183;
+use Test::More tests => 190;
my $class;
@@ -88,3 +88,5 @@ NaN:NaN
+inf:NaN
-inf:NaN
.p+0:NaN
+
+ 1 :1
diff --git a/t/from_oct-mbi.t b/t/from_oct-mbi.t
index 3a7833d..9e40cb5 100644
--- a/t/from_oct-mbi.t
+++ b/t/from_oct-mbi.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 344;
+use Test::More tests => 351;
my $class;
@@ -114,3 +114,5 @@ __END__
NaN:NaN
+inf:NaN
-inf:NaN
+
+ 1 :1
--
2.7.4