From 24cfe01d78f4caa04f25670bda192abb79d50ad5 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sat, 4 May 2019 11:21:42 -0400 Subject: [PATCH] Bug 22223: Try to not double encoded URIs in items.uri MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is just a POC and is not ready for inclusion (Filter.pm and naming need to be discussed). Test plan: Create 2 items, with uri: https://www.google.com/url?q=https://buttercup.pw https://www.google.com/url?q=https%3A%2F%2Fbuttercup.pw Go to the OPAC detail page of the bib record, see that the links are displayed how you entered them. Click on them and confirm that the uri/page is correct Signed-off-by: Séverine Queune JD amended patch: * Remove use Template::Plugin::Filter; * Fix license statement Signed-off-by: Tomas Cohen Arazi --- Koha/Template/Plugin/Filter.pm | 31 +++++++++++++++++++ .../prog/en/modules/catalogue/detail.tt | 9 ++++-- .../bootstrap/en/modules/opac-detail.tt | 7 +++-- 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 Koha/Template/Plugin/Filter.pm diff --git a/Koha/Template/Plugin/Filter.pm b/Koha/Template/Plugin/Filter.pm new file mode 100644 index 00000000000..0144f910536 --- /dev/null +++ b/Koha/Template/Plugin/Filter.pm @@ -0,0 +1,31 @@ +package Koha::Template::Plugin::Filter; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use base qw( Template::Plugin::Filter ); + +our $DYNAMIC = 1; + +sub no_double_encode { + my ( $self, $value ) = @_; + + $value =~ s/%25([0-9a-f]{2})/%$1/gi; + return $value; +} + +1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 320408596c5..63f9cbdbd6e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -2,6 +2,7 @@ [% USE Asset %] [% USE Koha %] [% USE KohaDates %] +[% USE Filter %] [% USE KohaPlugins %] [% USE AuthorisedValues %] [% USE Branches %] @@ -537,12 +538,16 @@ Note that permanent location is a code, and location may be an authval. [% IF ( itemdata_uri ) %] [% IF item.uri.split(' \| ').size > 1 %] - [% FOREACH uri IN item.uri.split(' \| ') %][% uri | html %]
[% END %] + [% FOREACH uri IN item.uri.split(' \| ') ~%] + [%~ uri_url_filtered = BLOCK %][% uri | url ~%][% END %] + [% uri | html %]
+ [%~ END %] [% ELSE %] [% IF item.uri %] - [% IF Koha.Preference('URLLinkText') %][% Koha.Preference('URLLinkText') | html %][% ELSE %]Link to resource[% END %] + [%~ uri_url_filtered = BLOCK %][% item.uri | url ~%][% END %] + [% IF Koha.Preference('URLLinkText') %][% Koha.Preference('URLLinkText') | html %][% ELSE %]Link to resource[% END %] [% END %] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index f6dc6014a25..5031cd6d19e 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -3,6 +3,7 @@ [% USE Math %] [% USE Koha %] [% USE KohaDates %] +[% USE Filter %] [% USE Branches %] [% USE TablesSettings %] [% USE AuthorisedValues %] @@ -1298,14 +1299,16 @@ [% IF trackclicks == 'track' || trackclicks == 'anonymous' %] [% uri | html %] [% ELSE %] - [% uri | html %] + [% uri_url_filtered = BLOCK %][% uri | url %][% END %] + [% uri | html %] [% END %] [% END %] [% ELSE %] [% IF trackclicks == 'track' || trackclicks == 'anonymous' %] [% ELSE %] - + [% uri_url_filtered = BLOCK %][% ITEM_RESULT.uri | url %][% END %] + [% END %] [% IF Koha.Preference('URLLinkText') %][% Koha.Preference('URLLinkText') | html %][% ELSE %]Link to resource[% END %] -- 2.34.1