From 07d5f76225a3acd905fecf53ccdc4f52474d7ffc Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 30 Jul 2018 12:57:58 +0200 Subject: [PATCH] Bug 21299: Introduce localReferer in [opac-]changelanguage.pl With the work from the former patch, we now have a nice and easy replace.. NOTE: The additional logic in opac-changelanguage.pl is now also applied to the intranet counterpart (changelanguage.pl). This effectively makes changelanguage.pl no longer refer to external URLs (as the opac already did by testing the referer). Might be just theoretical, but consistent. Test plan: Test changing language from various OPAC and staff locations. Include language=[some_language] in the URL before changing language. [Bonus] Test calling changelanguage.pl from another server. You should no longer be referred back to the calling server. (See below.) Signed-off-by: Marcel de Rooy Added link link somewhere on external server. Verified that without this patch, it hits the staff server and refers back to the caller. But with this patch, it refers to staff homepage. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- changelanguage.pl | 11 ++++------- opac/opac-changelanguage.pl | 22 ++++------------------ 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/changelanguage.pl b/changelanguage.pl index 3463c60645..c7a5c9493e 100755 --- a/changelanguage.pl +++ b/changelanguage.pl @@ -16,15 +16,12 @@ # along with Koha; if not, see . use Modern::Perl; - -use C4::Templates; use CGI qw ( -utf8 ); +use C4::Templates; +use Koha::Util; -my $query = new CGI; +my $query = new CGI; my $language = $query->param('language'); -my $url = $query->referer(); - -$url =~ s|(.)language=[\w-]*&?|$1|; -$url =~ s|(&\|\?)$||; # Remove extraneous ? or & +my $url = Koha::Util::localReferer($query, {remove_language => 1, staff => 1}); C4::Templates::setlanguagecookie( $query, $language, $url ); diff --git a/opac/opac-changelanguage.pl b/opac/opac-changelanguage.pl index 133e58efdb..2c01b287cc 100755 --- a/opac/opac-changelanguage.pl +++ b/opac/opac-changelanguage.pl @@ -16,26 +16,12 @@ # along with Koha; if not, see . use Modern::Perl; - -use C4::Templates; use CGI qw ( -utf8 ); +use C4::Templates; +use Koha::Util; -my $query = new CGI; +my $query = new CGI; my $language = $query->param('language'); - -# Detect where the user came from and save that url -my $requestedUrl = $query->url( -base => 1 ); - -# Use referer url if it matches $requestedUrl else use $requestedUrl as the url . -my $url = - $query->referer() =~ $requestedUrl ? $query->referer() : $requestedUrl; - -# warn "Language : $query // $language // $url"; - -# If language was set by an external URL the parameter -# 'language=' should be removed from url string, otherwise -# the language picker will not work -$url =~ s|(.)language=[\w-]*&?|$1|; -$url =~ s|(&\|\?)$||; # Remove extraneous ? or & +my $url = Koha::Util::localReferer($query, { remove_language => 1 }); C4::Templates::setlanguagecookie( $query, $language, $url ); -- 2.39.5