Compare commits

...

1 Commits
rawhide ... f25

Author SHA1 Message Date
Petr Písař 050ee2e060 Fix accepting numbers surrounded with a white space 2017-01-12 10:29:31 +01:00
2 changed files with 253 additions and 1 deletions

View File

@ -0,0 +1,245 @@
From 5c03061a16ec9af06e3d76d3757f9d3044d58d8e 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.
CPAN RT#119805
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
lib/Math/BigFloat.pm | 6 ++++++
lib/Math/BigInt.pm | 6 ++++++
t/from_bin-mbf.t | 15 ++++++++++++++-
t/from_hex-mbf.t | 15 ++++++++++++++-
t/from_oct-mbf.t | 15 ++++++++++++++-
5 files changed, 54 insertions(+), 3 deletions(-)
diff --git a/lib/Math/BigFloat.pm b/lib/Math/BigFloat.pm
index 190e2ee..1030c46 100644
--- a/lib/Math/BigFloat.pm
+++ b/lib/Math/BigFloat.pm
@@ -526,6 +526,7 @@ sub from_hex {
if ($str =~ s/
^
+ \s*
# sign
( [+-]? )
@@ -552,6 +553,7 @@ sub from_hex {
( \d+ (?: _ \d+ )* )
)?
+ \s*
$
//x)
{
@@ -611,6 +613,7 @@ sub from_oct {
if ($str =~ s/
^
+ \s*
# sign
( [+-]? )
@@ -634,6 +637,7 @@ sub from_oct {
( \d+ (?: _ \d+ )* )
)?
+ \s*
$
//x)
{
@@ -693,6 +697,7 @@ sub from_bin {
if ($str =~ s/
^
+ \s*
# sign
( [+-]? )
@@ -719,6 +724,7 @@ sub from_bin {
( \d+ (?: _ \d+ )* )
)?
+ \s*
$
//x)
{
diff --git a/lib/Math/BigInt.pm b/lib/Math/BigInt.pm
index 24b14c4..b0782ac 100644
--- a/lib/Math/BigInt.pm
+++ b/lib/Math/BigInt.pm
@@ -729,12 +729,14 @@ sub from_hex {
if ($str =~ s/
^
+ \s*
( [+-]? )
(0?x)?
(
[0-9a-fA-F]*
( _ [0-9a-fA-F]+ )*
)
+ \s*
$
//x)
{
@@ -780,11 +782,13 @@ sub from_oct {
if ($str =~ s/
^
+ \s*
( [+-]? )
(
[0-7]*
( _ [0-7]+ )*
)
+ \s*
$
//x)
{
@@ -830,12 +834,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 a8c7527..caaaa2f 100644
--- a/t/from_bin-mbf.t
+++ b/t/from_bin-mbf.t
@@ -3,19 +3,32 @@
use strict;
use warnings;
-use Test::More tests => 27;
+use Test::More tests => 1 + 26 * 4;
my $class;
BEGIN { $class = 'Math::BigFloat'; }
BEGIN { use_ok($class, '1.999710'); }
+my @data;
+my $space = "\t\r\n ";
+
while (<DATA>) {
s/#.*$//; # remove comments
s/\s+$//; # remove trailing whitespace
next unless length; # skip empty lines
my ($in0, $out0) = split /:/;
+
+ push @data, [ $in0, $out0 ],
+ [ $in0 . $space, $out0 ],
+ [ $space . $in0, $out0 ],
+ [ $space . $in0 . $space, $out0 ];
+}
+
+for my $entry (@data) {
+ my ($in0, $out0) = @$entry;
+
my $x;
my $test = qq|\$x = $class -> from_bin("$in0");|;
diff --git a/t/from_hex-mbf.t b/t/from_hex-mbf.t
index b45917a..8fa8a0b 100644
--- a/t/from_hex-mbf.t
+++ b/t/from_hex-mbf.t
@@ -3,19 +3,32 @@
use strict;
use warnings;
-use Test::More tests => 27;
+use Test::More tests => 1 + 26 * 4;
my $class;
BEGIN { $class = 'Math::BigFloat'; }
BEGIN { use_ok($class, '1.999710'); }
+my @data;
+my $space = "\t\r\n ";
+
while (<DATA>) {
s/#.*$//; # remove comments
s/\s+$//; # remove trailing whitespace
next unless length; # skip empty lines
my ($in0, $out0) = split /:/;
+
+ push @data, [ $in0, $out0 ],
+ [ $in0 . $space, $out0 ],
+ [ $space . $in0, $out0 ],
+ [ $space . $in0 . $space, $out0 ];
+}
+
+for my $entry (@data) {
+ my ($in0, $out0) = @$entry;
+
my $x;
my $test = qq|\$x = $class -> from_hex("$in0");|;
diff --git a/t/from_oct-mbf.t b/t/from_oct-mbf.t
index 7e58454..19392f2 100644
--- a/t/from_oct-mbf.t
+++ b/t/from_oct-mbf.t
@@ -3,19 +3,32 @@
use strict;
use warnings;
-use Test::More tests => 27;
+use Test::More tests => 1 + 26 * 4;
my $class;
BEGIN { $class = 'Math::BigFloat'; }
BEGIN { use_ok($class, '1.999710'); }
+my @data;
+my $space = "\t\r\n ";
+
while (<DATA>) {
s/#.*$//; # remove comments
s/\s+$//; # remove trailing whitespace
next unless length; # skip empty lines
my ($in0, $out0) = split /:/;
+
+ push @data, [ $in0, $out0 ],
+ [ $in0 . $space, $out0 ],
+ [ $space . $in0, $out0 ],
+ [ $space . $in0 . $space, $out0 ];
+}
+
+for my $entry (@data) {
+ my ($in0, $out0) = @$entry;
+
my $x;
my $test = qq|\$x = $class -> from_oct("$in0");|;
--
2.7.4

View File

@ -2,12 +2,15 @@ Name: perl-Math-BigInt
%global cpan_version 1.999727
# Keep 4-digit version to compete with perl.spec
Version: %(echo %{cpan_version} | sed 's/\(\.....\)/\1./')
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Arbitrary-size integer and float mathematics
License: GPL+ or Artistic
Group: Development/Libraries
URL: http://search.cpan.org/dist/Math-BigInt/
Source0: http://www.cpan.org/authors/id/P/PJ/PJACKLAM/Math-BigInt-%{cpan_version}.tar.gz
# Fix accepting numbers surrounded with a white space, bug #1412052,
# CPAN RT#119805, fixed in 1.999808
Patch0: Math-BigInt-1.999727-Ignore-leading-and-trailing-white-spaces-for-non-dec.patch
BuildArch: noarch
BuildRequires: coreutils
BuildRequires: findutils
@ -81,6 +84,7 @@ This provides Perl modules for arbitrary-size integer and float mathematics.
%prep
%setup -q -n Math-BigInt-%{cpan_version}
%patch0 -p1
# This core module must be buildable without non-core modules at bootstrap.
%if !%{defined perl_bootstrap}
# Remove bundled modules
@ -110,6 +114,9 @@ make test
%{_mandir}/man3/*
%changelog
* Thu Jan 12 2017 Petr Pisar <ppisar@redhat.com> - 1.9997.27-2
- Fix accepting numbers surrounded with a white space (bug #1412052)
* Tue Nov 08 2016 Petr Pisar <ppisar@redhat.com> - 1.9997.27-1
- 1.999727 bump