Bug 18946 - Change language from external web fails
authorKaram Qubsi <karamqubsi@gmail.com>
Tue, 18 Jul 2017 16:06:48 +0000 (00:06 +0800)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 1 Sep 2017 16:02:26 +0000 (13:02 -0300)
How to reproduce:
1. Get a multilingüal Koha like
http://demo1.orex.es/cgi-bin/koha/opac-changelanguage.pl?language=en
http://demo1.orex.es/cgi-bin/koha/opac-changelanguage.pl?language=es-ES

2. Copy that urls to any web page in an other domain -it must be in some
host - and try to link to the spanish or english version,it will keep you in the same position.

3. Apply this patch and try again , everything should work fine .

Signed-off-by: Hugo Agud <hagud@orex.es>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
opac/opac-changelanguage.pl

index 9c68ab4..689f4d4 100755 (executable)
@@ -22,7 +22,10 @@ use CGI qw ( -utf8 );
 
 my $query    = new CGI;
 my $language = $query->param('language');
-my $url      = $query->referer() || '/';
+# 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";