From 13f7f52484f140c7e8004a8cd168e84f80511114 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 27 Apr 2015 11:50:55 +0200 Subject: [PATCH] Bug 14044: Escape json strings for patron searches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In a couple of patron searches, the address is displayed. If the address contain invalid json characters, DataTables won't manage to parse the results and display them. This patch makes the templates more readable by creating a BLOCK instead of a long line and escape the invalid json characters calling the TT plugin (To.json). Test plan: Edit a patron and add something like: patron
\123 ☎ ⚑ in the address field. Search for this patron using the main patron search (members/member.pl) and the guarantor search. Confirm that a result with this patron is correctly displayed. Regression test: Since Koha::Template::Plugin::To::json is modified, confirm that the add users to basket search (on acqui/basket.pl?basketno=X click on the "Add user" button) still works as expected. --- Koha/Template/Plugin/To.pm | 4 +++- .../prog/en/modules/members/tables/guarantor_search.tt | 14 +++++++++++++- .../prog/en/modules/members/tables/members_results.tt | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Koha/Template/Plugin/To.pm b/Koha/Template/Plugin/To.pm index 41adc70..6bf56b1 100644 --- a/Koha/Template/Plugin/To.pm +++ b/Koha/Template/Plugin/To.pm @@ -27,7 +27,9 @@ sub json { my ( $self, $value ) = @_; my $json = JSON->new->allow_nonref(1); - return $json->encode( $value ); + $json = $json->encode($value); + $json =~ s/^"|"$//g; # Remove quotes around the strings + return $json; } 1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/guarantor_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/guarantor_search.tt index dab1f23..e9126a3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/guarantor_search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/guarantor_search.tt @@ -1,4 +1,5 @@ [% USE To %] +[% USE Branches %] [% USE KohaDates %] { "sEcho": [% sEcho %], @@ -14,10 +15,21 @@ "dt_dateofbirth": "[% data.dateofbirth | $KohaDates %]", "dt_address": - "[% data.streetnumber %] [% data.address | html %] [% data.address2 | html %] [% data.city | html %] [% data.state | html %] [% data.zipcode | html %] [% data.country | html %] [% data.branchcode %]", + "[% INCLUDE escape_address data=data %]", "dt_action": "Select" }[% UNLESS loop.last %],[% END %] [% END %] ] } +[% BLOCK escape_address %] +[%~ SET address = data.streetnumber _ ' ' %] +[%~ IF data.address %][% SET address = address _ data.address _ ' ' %][% END %] +[%~ IF data.address2 %][% SET address = address _ data.address2 _ ' ' %][% END %] +[%~ IF data.city %][% SET address = address _ data.city _ ' ' %][% END %] +[%~ IF data.state %][% SET address = address _ data.state _ ' ' %][% END %] +[%~ IF data.zipcode %][% SET address = address _ data.zipcode _ ' ' %][% END %] +[%~ IF data.country %][% SET address = address _ data.country _ ' ' %][% END %] +[%~ SET address = address _ Branches.GetName( data.branchcode ) %] +[%~ To.json( address ) | html ~%] +[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/members_results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/members_results.tt index e56d41e..236dcc3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/members_results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/members_results.tt @@ -14,7 +14,7 @@ "dt_cardnumber": "[% data.cardnumber | html %]", "dt_name": - "[% INCLUDE 'patron-title.inc' borrowernumber = data.borrowernumber category_type = data.category_type firstname = data.firstname surname = data.surname othernames = data.othernames invert_name = 1 %]
[% IF ( data.streetnumber ) %][% To.json( data.streetnumber ) | html %] [% END %][% IF ( data.streettype ) %][% To.json( AuthorisedValues.GetByCode( 'ROADTYPE', data.streettype ) ) | html %] [% END %][% To.json( data.address ) | html %][% IF ( data.address2 ) %]
[% To.json( data.address2 ) | html %][% END %][% IF ( data.city || data.state || data.zipcode || data.country) %]
[% END %][% IF ( data.city ) %][% To.json( data.city ) | html %][% IF ( data.state ) %],[% END %][% END %][% IF ( data.state ) %] [% To.json( data.state ) | html %][% END %] [% IF ( data.zipcode ) %] [% To.json( data.zipcode ) | html %][% END %][% IF ( data.country ) %], [% To.json( data.country ) | html %][% END %][% IF data.email %]
Email: [% data.email %][% END %]
", + "[% INCLUDE 'patron-title.inc' borrowernumber = data.borrowernumber category_type = data.category_type firstname = data.firstname surname = data.surname othernames = data.othernames invert_name = 1 %]
[% INCLUDE escape_address data = data %]
", "dt_category": "[% data.category_description |html %] ([% data.category_type |html %])", "dt_branch": @@ -35,3 +35,10 @@ [% END %] ] } +[% BLOCK escape_address %] +[%~ SET address = data.streetnumber _ ' ' %] +[%~ IF data.streettype %][% address = address _ AuthorisedValues.GetByCode( 'ROADTYPE', data.streettype ) _ ' ' %][% END %] +[%~ IF data.address %][% address = address _ data.address _ ' ' %][% END %] +[%~ IF data.address2 %][% address = address _ data.address2 _ ' ' %][% END %] +[%~ To.json( address ) | html ~%] +[% END %] -- 2.1.0