Bug 26127: local_referer should not compare with OPACBaseURL case insensitive
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 3 Aug 2020 13:07:24 +0000 (15:07 +0200)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 18 Aug 2020 12:47:44 +0000 (14:47 +0200)
In our test data we have OPACBaseURL that is filled with http://kohadev.myDNSname.org:8080,
but the CGI referer in local_referer is lowercase
We should compare it without case sensitivity

Test plan:
- Use koha-testing-docker
- Notice the value of OPACBaseURL
=> http://kohadev.myDNSname.org:8080
- Use the "reports a problem" feature at the OPAC
- Notice that the "Problem found on page" is correctly filled with the
referer

Signed-off-by: Kelly McElligott <kelly@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Koha/Util/Navigation.pm
t/Koha/Util/Navigation.t

index 6f9b304..75bde71 100644 (file)
@@ -59,7 +59,7 @@ sub local_referer {
 
     # Try ..BaseURL first, otherwise use CGI::url
     if( $base ) {
-        if( substr($referer, 0, length($base)) eq $base &&
+        if( $referer =~ m|^\Q$base\E|i &&
             $referer =~ /\/cgi-bin\/koha\// )
         {
             $rv = substr( $referer, length($base) );
index 466f296..9ff50ea 100644 (file)
@@ -7,7 +7,7 @@ use t::lib::Mocks;
 use Koha::Util::Navigation;
 
 subtest 'Tests for local_referer' => sub {
-    plan tests => 10;
+    plan tests => 11;
 
     my ( $referer, $base );
     my $cgi = Test::MockObject->new;
@@ -26,6 +26,10 @@ subtest 'Tests for local_referer' => sub {
     $referer = 'https://koha.nl/custom/stuff';
     is( Koha::Util::Navigation::local_referer($cgi), '/', 'custom url' );
 
+    t::lib::Mocks::mock_preference('OPACBaseURL', 'http://kohadev.myDNSname.org:8080');
+    $referer = "http://kohadev.mydnsname.org:8080$search";
+    is( Koha::Util::Navigation::local_referer($cgi), $search, 'local_referer is comparing $OPACBaseURL case insensitive' );
+
     # trailing backslash
     t::lib::Mocks::mock_preference('OPACBaseURL', 'http://koha.nl/' );
     $referer = "http://koha.nl$search";