Bugzilla – Attachment 75883 Details for
Bug 20886
Koha::Object::TO_JSON indiscriminately casting to integer
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20886: Do not cast undef to 0 (TO_JSON)
Bug-20886-Do-not-cast-undef-to-0-TOJSON.patch (text/plain), 2.58 KB, created by
Tomás Cohen Arazi (tcohen)
on 2018-06-07 14:16:30 UTC
(
hide
)
Description:
Bug 20886: Do not cast undef to 0 (TO_JSON)
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2018-06-07 14:16:30 UTC
Size:
2.58 KB
patch
obsolete
>From b10c5c95e79b12817461d170acefbe4098733276 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 6 Jun 2018 11:12:24 -0300 >Subject: [PATCH] Bug 20886: Do not cast undef to 0 (TO_JSON) > >We should not cast undefined values to 0. > >Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >This was a bug I introduced. I think the fix is right, and if something >gets broken for this, it means it was making the wrong assumptions on >the data. >--- > Koha/Object.pm | 5 ++++- > t/db_dependent/Koha/Object.t | 5 ++++- > 2 files changed, 8 insertions(+), 2 deletions(-) > >diff --git a/Koha/Object.pm b/Koha/Object.pm >index b9208f07ac..e35ff0b85e 100644 >--- a/Koha/Object.pm >+++ b/Koha/Object.pm >@@ -22,6 +22,7 @@ use Modern::Perl; > > use Carp; > use Mojo::JSON; >+use Scalar::Util qw( looks_like_number ); > use Try::Tiny; > > use Koha::Database; >@@ -241,7 +242,9 @@ sub TO_JSON { > ? Mojo::JSON->true > : Mojo::JSON->false; > } >- elsif ( _numeric_column_type( $columns_info->{$col}->{data_type} ) ) { >+ elsif ( _numeric_column_type( $columns_info->{$col}->{data_type} ) >+ and looks_like_number( $unblessed->{$col} ) >+ ) { > > # TODO: Remove once the solution for > # https://rt.cpan.org/Ticket/Display.html?id=119904 >diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t >index 7998b05e7f..a00083a5b7 100755 >--- a/t/db_dependent/Koha/Object.t >+++ b/t/db_dependent/Koha/Object.t >@@ -161,7 +161,7 @@ subtest 'discard_changes' => sub { > > subtest 'TO_JSON tests' => sub { > >- plan tests => 7; >+ plan tests => 8; > > $schema->storage->txn_begin; > >@@ -169,6 +169,7 @@ subtest 'TO_JSON tests' => sub { > my $borrowernumber = $builder->build( > { source => 'Borrower', > value => { lost => 1, >+ sms_provider_id => undef, > gonenoaddress => 0, > updated_on => $dt, > lastseen => $dt, } })->{borrowernumber}; >@@ -185,6 +186,8 @@ subtest 'TO_JSON tests' => sub { > ok( $gonenoaddress->isa('JSON::PP::Boolean'), 'Boolean attribute type is correct' ); > is( $gonenoaddress, 0, 'Boolean attribute value is correct (false)' ); > >+ is( $patron->TO_JSON->{sms_provider_id}, undef, 'Undef values should not be casted to 0' ); >+ > ok( !isvstring($patron->borrowernumber), 'Integer values are not coded as strings' ); > > my $rfc3999_regex = qr/ >-- >2.17.1
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 20886
:
75857
|
75869
|
75875
| 75883