From 7a53c5f04cf2bb03734c82e9f964f108f9198d28 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 3 Aug 2020 15:07:24 +0200 Subject: [PATCH] Bug 26127: local_referer should not compare with OPACBaseURL case insensitive 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 Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- Koha/Util/Navigation.pm | 2 +- t/Koha/Util/Navigation.t | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Koha/Util/Navigation.pm b/Koha/Util/Navigation.pm index 6f9b304b5c..75bde71fa1 100644 --- a/Koha/Util/Navigation.pm +++ b/Koha/Util/Navigation.pm @@ -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) ); diff --git a/t/Koha/Util/Navigation.t b/t/Koha/Util/Navigation.t index 466f296e60..9ff50ea238 100644 --- a/t/Koha/Util/Navigation.t +++ b/t/Koha/Util/Navigation.t @@ -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"; -- 2.39.5