Bugzilla – Attachment 69982 Details for
Bug 15770
Number::Format issues with large numbers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15770: Do not format numbers if too big
Bug-15770-Do-not-format-numbers-if-too-big.patch (text/plain), 2.19 KB, created by
Jonathan Druart
on 2017-12-20 23:33:07 UTC
(
hide
)
Description:
Bug 15770: Do not format numbers if too big
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2017-12-20 23:33:07 UTC
Size:
2.19 KB
patch
obsolete
>From 77815f4153df90e21cfc5bab4d190b229896adb3 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 20 Dec 2017 20:29:29 -0300 >Subject: [PATCH] Bug 15770: Do not format numbers if too big > >At several places we got the following error if we use numbers too big >for Number::Format >Template process failed: undef error - round() overflow. Try smaller >precision or use Math::BigFloat at /home/koha/src/Koha/Number/Price.pm line 44 > >It make the app explodes. >The goal here is to handle these errors gracefully and easily. > >Test plan: >- Add a manual fine to a patron of 100000000000000 >- Create a patron category with an enrolment fee of 123456789012345 >--- > Koha/Number/Price.pm | 5 +++++ > t/Number/Price.t | 4 +++- > 2 files changed, 8 insertions(+), 1 deletion(-) > >diff --git a/Koha/Number/Price.pm b/Koha/Number/Price.pm >index 77d5b21..8e08607 100644 >--- a/Koha/Number/Price.pm >+++ b/Koha/Number/Price.pm >@@ -41,6 +41,11 @@ sub format { > > my $format_params = $self->_format_params( $params ); > >+ # To avoid the system to crash, we will not format big number >+ # We divide per 100 because we want to keep the default DECIMAL_DIGITS (2) >+ # error - round() overflow. Try smaller precision or use Math::BigFloat >+ return $self->value if $self->value > Number::Format::MAX_INT/100; >+ > return Number::Format->new(%$format_params)->format_price($self->value); > } > >diff --git a/t/Number/Price.t b/t/Number/Price.t >index 68365c3..ea58488 100644 >--- a/t/Number/Price.t >+++ b/t/Number/Price.t >@@ -1,6 +1,6 @@ > use Modern::Perl; > >-use Test::More tests => 30; >+use Test::More tests => 31; > > use Test::MockModule; > use t::lib::Mocks; >@@ -33,6 +33,8 @@ is( Koha::Number::Price->new(3)->format( $format ), '3.00', 'US: format 3' ); > is( Koha::Number::Price->new(1234567890)->format( $format ), > '1,234,567,890.00', 'US: format 1234567890' ); > >+is( Koha::Number::Price->new(100000000000000)->format, '100000000000000', 'Numbers too big are not formatted'); >+ > # FIXME This should be display symbol, but it was the case before the creation of this module > is( Koha::Number::Price->new->format( { %$format, with_symbol => 1 } ), > '0.00', 'US: format 0 with symbol' ); >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15770
:
69982
|
70753
|
70762