Skip Menu |

This queue is for tickets about the Math-BigInt CPAN distribution.

Report information
The Basics
Id: 119805
Status: resolved
Priority: 0/
Queue: Math-BigInt

People
Owner: Nobody in particular
Requestors: stewart [...] linux.vnet.ibm.com
Cc:
AdminCc:

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



Subject: Regression in ignoring trailing whitespace: Math::BigInt->new('0x10\n\t\t')
Date: Wed, 11 Jan 2017 15:29:39 +1100
To: bug-Math-BigInt [...] rt.cpan.org
From: Stewart Smith <stewart [...] linux.vnet.ibm.com>
The Math::BigInt manual states that leading and trailing whitespace is ignored, and in fact this has been the behaviour for many years. However, in recent Math::BigInt (that has shipped in Linux distributions... e.g. Fedora 25), this behaviour is broken, which breaks our tools that rely on this. With Math::BigInt 1.999727: 'use Math::BigInt; print Dumper(Math::BigInt->new("0x10\n\t\t\t"));'; $VAR1 = bless( { 'sign' => 'NaN', 'value' => [ 0 ] }, 'Math::BigInt' ); With Math::BigInt 1.9993: 'use Math::BigInt; print Dumper(Math::BigInt->new("0x10\n\t\t\t"));'; $VAR1 = bless( { 'sign' => '+', 'value' => [ 16 ] }, 'Math::BigInt' ); The first version to exhibit this buggy behaviour was 1.999712, with 1.999710 and 1.9997_11 both not having the bug. All versions after 1.999712, including the latest, 1.999807 exhibit the bug. -- Stewart Smith OPAL Architect, IBM.
From: ppisar [...] redhat.com
Dne St 11.led.2017 03:31:15, stewart@linux.vnet.ibm.com napsal(a): Show quoted text
> The Math::BigInt manual states that leading and trailing whitespace is > ignored, and in fact this has been the behaviour for many years. > > However, in recent Math::BigInt (that has shipped in Linux > distributions... e.g. Fedora 25), this behaviour is broken,
Attached patch fixes is by accepting leading and trailing space by from_hex(), from_bin(), and from_oct() in Math::BigInt and Math::Float.
Subject: 0001-Ignore-leading-and-trailing-white-spaces-for-non-dec.patch
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