Bugzilla – Attachment 56917 Details for
Bug 17502
Add type check to output_pref and use exceptions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17502: Resolve internal server error on 0000-00-00 (with Plack)
Bug-17502-Resolve-internal-server-error-on-0000-00.patch (text/plain), 4.14 KB, created by
Marcel de Rooy
on 2016-10-27 12:42:18 UTC
(
hide
)
Description:
Bug 17502: Resolve internal server error on 0000-00-00 (with Plack)
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2016-10-27 12:42:18 UTC
Size:
4.14 KB
patch
obsolete
>From 03b987187b8a551c461f7a28f4c40fa698796147 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 27 Oct 2016 09:11:03 +0200 >Subject: [PATCH] Bug 17502: Resolve internal server error on 0000-00-00 (with > Plack) >Content-Type: text/plain; charset=utf-8 > >This patch makes the following changes: > >[1] In Koha/DateUtils.pm, sub output_pref: > > Add a test if $dt is really a DateTime before calling method ymd. > Preventing a crash like: > Can't locate object method "ymd" via package "dateonly" > Change [2] fixes a specific call where this went wrong, but this test > may still catch one or two other occurrences in the code. > >[2] In C4/Search.pm, sub searchResults: > Scalarize the return value of dt_from_string as a hash parameter for > output_pref. Like: > { dt => scalar dt_from_string( $date ), dateonly => 1 } > If the sub would return undef (without adding scalar), the hash would > have an odd number of elements. (A warning is suppressed in C4/Search.) > For a value of 0000-00-00 in item.onloan, this resolves an internal > server error on a search with this item in the results. > >[3] Adds a few unit tests in t/DateUtils.t. > >Note: I opened up another report to prevent having 000-00-00 in item dates. > >Test plan: >[1] Without this patch: Put a 0000-00-00 in items.onloan for one item. > (Make 952 $q visible and just enter some text in it.) >[2] Verify that a search on opac/intranet that includes this item, results > in a crash. (Plack will just say: Internal server error.) > NOTE: With Jessie and Plack, the search crashes. On a Wheezy without > Plack, it did not crash. >[3] Apply this patch. (Restart Plack.) >[4] Verify that the same search now does not fail. >[5] Run the adjusted unit test t/DateUtils.t >--- > C4/Search.pm | 2 +- > Koha/DateUtils.pm | 2 +- > t/DateUtils.t | 9 ++++++++- > 3 files changed, 10 insertions(+), 3 deletions(-) > >diff --git a/C4/Search.pm b/C4/Search.pm >index ef61338..ca4b66f 100644 >--- a/C4/Search.pm >+++ b/C4/Search.pm >@@ -2082,7 +2082,7 @@ sub searchResults { > { > $onloan_count++; > my $key = $prefix . $item->{onloan} . $item->{barcode}; >- $onloan_items->{$key}->{due_date} = output_pref( { dt => dt_from_string( $item->{onloan} ), dateonly => 1 } ); >+ $onloan_items->{$key}->{due_date} = output_pref( { dt => scalar dt_from_string( $item->{onloan} ), dateonly => 1 } ); > $onloan_items->{$key}->{count}++ if $item->{$hbranch}; > $onloan_items->{$key}->{branchname} = $item->{branchname}; > $onloan_items->{$key}->{location} = $shelflocations->{ $item->{location} }; >diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm >index 51d3d93..1bc4ec7 100644 >--- a/Koha/DateUtils.pm >+++ b/Koha/DateUtils.pm >@@ -219,7 +219,7 @@ sub output_pref { > carp "Invalid date '$str' passed to output_pref\n" if $@; > } > >- return unless defined $dt; >+ return unless defined $dt && ref($dt) eq 'DateTime'; > > # FIXME: see bug 13242 => no TZ for dates 'infinite' > if ( $dt->ymd !~ /^9999/ ) { >diff --git a/t/DateUtils.t b/t/DateUtils.t >index eede4a0..a3dc6b3 100755 >--- a/t/DateUtils.t >+++ b/t/DateUtils.t >@@ -4,7 +4,7 @@ use DateTime::TimeZone; > > use C4::Context; > >-use Test::More tests => 60; >+use Test::More tests => 63; > > use Test::MockModule; > use Test::Warn; >@@ -219,6 +219,13 @@ is( output_pref( { dt => $dt, dateonly => 1 } ), '01/01/1900', 'dt_from_string s > $dt = dt_from_string('2015-01-31 01:02:03'); > is( output_pref( {dt => $dt} ), '31/01/2015 01:02', 'dt_from_string should fallback to sql format' ); > >+# output_pref with no parameters, single parameter (no hash) >+is( output_pref(), undef, 'output_pref without parameters' ); >+is( output_pref( 'no_dt' ), undef, 'Passed single invalid dt to output_pref' ); >+ >+# pass invalid dt via hash >+is( output_pref({ dt => 'no_dt' }), undef, 'Passed invalid dt in hash to output_pref' ); >+ > # output_pref with str parameter > is( output_pref( { 'str' => $testdate_iso, dateformat => 'iso', dateonly => 1 } ), $testdate_iso, 'output_pref should handle correctly the iso parameter' ); > my $output_for_invalid_date; >-- >1.7.10.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 17502
:
56916
|
56917
|
57597
|
61458
|
61510
|
61518
|
61519
|
62168
|
62169
|
62408
|
62409
|
62410