Bugzilla – Attachment 26151 Details for
Bug 11302
Template::output should deal with object
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11302: Template::output should deal with objects
Bug-11302-Templateoutput-should-deal-with-objects.patch (text/plain), 3.20 KB, created by
Jacek Ablewicz
on 2014-03-12 10:01:43 UTC
(
hide
)
Description:
Bug 11302: Template::output should deal with objects
Filename:
MIME Type:
Creator:
Jacek Ablewicz
Created:
2014-03-12 10:01:43 UTC
Size:
3.20 KB
patch
obsolete
>From e740585f9abe01c3b67ded1f687a8f464449da27 Mon Sep 17 00:00:00 2001 >From: Jacek Ablewicz <abl@biblos.pk.edu.pl> >Date: Wed, 12 Mar 2014 10:05:08 +0100 >Subject: [PATCH] Bug 11302: Template::output should deal with objects > >If a ref is not HASH or ARRAY, C4::Template::output assumes it >is a scalar. Which is wrong, it could be an object. > >Note: this is yet another / alternative take on the problem, >with only bare minimum changes made to the code base, so >this (counter-)patch - while not pretty - hopefully should be >less regression-prone. Right now, the only white-listed object >this patch deals with is 'Koha::AdditionalField' introduced >by bug 10855. In case it tests OK, without any regressions, we can >add another objects (C4::Category etc.) later on. > >Test plan: >1) apply bug 10855 first; observe that non-ascii characters >(in authorized category names or additional field labels) are not >properly handled, >2) apply patch, >3) ensure that encoding of non-ascii characters for features added >by 10855 got fixed, >4) there should be no character-encoding-related regressions >of any kind appearing anywhere in the system. >--- > C4/Templates.pm | 26 ++++++++++++++++++-------- > 1 file changed, 18 insertions(+), 8 deletions(-) > >diff --git a/C4/Templates.pm b/C4/Templates.pm >index 2d2304f..1c7dbfe 100644 >--- a/C4/Templates.pm >+++ b/C4/Templates.pm >@@ -117,10 +117,11 @@ sub output { > # and clean any utf8 mess > for my $k ( keys %{ $self->{VARS} } ) { > $vars->{$k} = $self->{VARS}->{$k}; >- if (ref($vars->{$k}) eq 'ARRAY'){ >+ my $rt = ref($vars->{$k}); >+ if ($rt eq 'ARRAY') { > utf8_arrayref($vars->{$k}); > } >- elsif (ref($vars->{$k}) eq 'HASH'){ >+ elsif ($rt eq 'HASH' || _utf8_is_whitelisted_object($rt)) { > utf8_hashref($vars->{$k}); > } > else { >@@ -137,11 +138,12 @@ sub output { > sub utf8_arrayref { > my $arrayref = shift; > foreach my $element (@$arrayref){ >- if (ref($element) eq 'ARRAY'){ >+ my $rt = ref($element); >+ if ($rt eq 'ARRAY'){ > utf8_arrayref($element); > next; > } >- if (ref($element) eq 'HASH'){ >+ if ($rt eq 'HASH' || _utf8_is_whitelisted_object($rt)) { > utf8_hashref($element); > next; > } >@@ -152,19 +154,27 @@ sub utf8_arrayref { > sub utf8_hashref { > my $hashref = shift; > for my $key (keys %{$hashref}){ >- if (ref($hashref->{$key}) eq 'ARRAY'){ >+ my $rt = ref($hashref->{$key}); >+ if ($rt eq 'ARRAY'){ > utf8_arrayref($hashref->{$key}); > next; > } >- if (ref($hashref->{$key}) eq 'HASH'){ >+ if ($rt eq 'HASH' || _utf8_is_whitelisted_object($rt)) { > utf8_hashref($hashref->{$key}); > next; > } > utf8::encode($hashref->{$key}) if utf8::is_utf8($hashref->{$key}); > } > } >- >- >+ >+sub _utf8_is_whitelisted_object { >+ my $rt = shift; >+ $rt eq '' && return(0); >+ my @whitelist = qw( Koha::AdditionalField ); >+ map { $_ eq $rt && return(1); } @whitelist; >+ 0; >+} >+ > # FIXME - this is a horrible hack to cache > # the current known-good language, temporarily > # put in place to resolve bug 4403. It is >-- >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 11302
:
23154
| 26151