Bugzilla – Attachment 23154 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), 5.26 KB, created by
Jonathan Druart
on 2013-11-26 08:41:05 UTC
(
hide
)
Description:
Bug 11302: Template::output should deal with objects
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2013-11-26 08:41:05 UTC
Size:
5.26 KB
patch
obsolete
>From 718c62acb7455da9e3f84dc687c9509fc562ea22 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Mon, 25 Nov 2013 16:39:09 +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. > >At least the member 'description' of the C4::Category object should be >encoded. > >Test plan: >Before applying the patch >- translate a template for a language >- create a patron category with a no-ASCII character >- got the patron home page and select the translated language >- you should see a broken encoding >Apply the patch >- refresh the page >- all looks good now >--- > C4/Templates.pm | 70 ++++++++++---------- > .../prog/en/includes/patron-toolbar.inc | 2 +- > 2 files changed, 36 insertions(+), 36 deletions(-) > >diff --git a/C4/Templates.pm b/C4/Templates.pm >index 2d2304f..352ecbb 100644 >--- a/C4/Templates.pm >+++ b/C4/Templates.pm >@@ -34,7 +34,9 @@ use Template; > use Template::Constants qw( :debug ); > use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description accept_language ); > >+use Encode; > use C4::Context; >+use Scalar::Util qw( reftype ); > > __PACKAGE__->mk_accessors(qw( theme activethemes preferredtheme lang filename htdocs interface vars)); > >@@ -117,15 +119,7 @@ sub output { > # and clean any utf8 mess > for my $k ( keys %{ $self->{VARS} } ) { > $vars->{$k} = $self->{VARS}->{$k}; >- if (ref($vars->{$k}) eq 'ARRAY'){ >- utf8_arrayref($vars->{$k}); >- } >- elsif (ref($vars->{$k}) eq 'HASH'){ >- utf8_hashref($vars->{$k}); >- } >- else { >- utf8::encode($vars->{$k}) if utf8::is_utf8($vars->{$k}); >- } >+ utf8_struct( $vars->{$k} ); > } > my $data; > # binmode( STDOUT, ":utf8" ); >@@ -134,37 +128,43 @@ sub output { > return $data; > } > >-sub utf8_arrayref { >- my $arrayref = shift; >- foreach my $element (@$arrayref){ >- if (ref($element) eq 'ARRAY'){ >- utf8_arrayref($element); >- next; >- } >- if (ref($element) eq 'HASH'){ >- utf8_hashref($element); >- next; >+ >+# FIXME It is not the best to create a whitelist or a blacklist here... >+#my @backlist = ( qr|^Date|, qr|^Koha::Schema| ); >+my @whitelist = qw( C4::Category ); >+sub utf8_struct { >+ my $element = shift; >+ my $ref = ref $element; >+ if ( $ref and $ref eq 'ARRAY' ) { >+ foreach my $elt ( @$element ) { >+ $elt = utf8_struct( $elt ); > } >- utf8::encode($element) if utf8::is_utf8($element); >- } >-} >- >-sub utf8_hashref { >- my $hashref = shift; >- for my $key (keys %{$hashref}){ >- if (ref($hashref->{$key}) eq 'ARRAY'){ >- utf8_arrayref($hashref->{$key}); >- next; >+ return $element; >+ } elsif ( $ref and $ref eq 'HASH' ) { >+ while ( my ($k, $val) = each %{$element} ) { >+ $element->{$k} = utf8_struct( $val ); > } >- if (ref($hashref->{$key}) eq 'HASH'){ >- utf8_hashref($hashref->{$key}); >- next; >+ return $element; >+ } else { >+ if ( not $element >+ or not reftype( $element ) >+ or reftype( $element ) eq 'SCALAR' ) { >+ return Encode::is_utf8($element) >+ ? Encode::encode_utf8($element) >+ : $element; >+ } else { >+ my $ref = ref( $element ); >+ if ( grep { $ref } @whitelist ) { >+ while ( my ( $member, $value ) = each %$element ) { >+ $value = utf8_struct( $value ); >+ $element->{$member} = $value; >+ } >+ } >+ return $element; > } >- utf8::encode($hashref->{$key}) if utf8::is_utf8($hashref->{$key}); > } > } >- >- >+ > # FIXME - this is a horrible hack to cache > # the current known-good language, temporarily > # put in place to resolve bug 4403. It is >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc >index 8d36da3..c8ff82d 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc >@@ -4,7 +4,7 @@ > <button class="btn btn-small dropdown-toggle" data-toggle="dropdown"><i class="icon-plus"></i> New patron <span class="caret"></span></button> > <ul class="dropdown-menu"> > [% IF ( AddPatronLists_categorycode ) %] >- [% FOREACH categorie IN categories %]<li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&categorycode=[% categorie.categorycode %]">[% categorie.description | html_entity %]</a></li>[% END %] >+ [% FOREACH categorie IN categories %]<li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&categorycode=[% categorie.categorycode %]">[% categorie.description %]</a></li>[% END %] > [% ELSE %] > <li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&category_type=A">Adult patron</a></li> > <li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&category_type=C">Child patron</a></li> >-- >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