From 4fa7e90b0e650cd5e9e33a708b89052238197f30 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 27 Jun 2016 13:32:31 +0100 Subject: [PATCH] Bug 16813: Allow empty string for OPACBaseURL MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The pref is prefixed by 'http://', but it should not when the pref is set to an empty string. This will fix the bug raised on bug 14790 comment 14. Test plan: Empty OPACBaseURL and confirm that it's save as it in DB Signed-off-by: Hector Castro OPACBaseURL is saved up empty. Prefix http:// is not saved anymore Signed-off-by: Katrin Fischer Signed-off-by: Kyle M Hall (cherry picked from commit e9b6a5e31e1bc225a6e620dcefbd9545bb6d98bf) Signed-off-by: Frédéric Demians --- C4/Context.pm | 2 +- t/db_dependent/Context.t | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/C4/Context.pm b/C4/Context.pm index 1bf23c23ce..4ff47af54a 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -615,7 +615,7 @@ sub set_preference { $value = 0 if ( $type && $type eq 'YesNo' && $value eq '' ); # force explicit protocol on OPACBaseURL - if ( $variable eq 'opacbaseurl' && substr( $value, 0, 4 ) !~ /http/ ) { + if ( $variable eq 'opacbaseurl' && $value && substr( $value, 0, 4 ) !~ /http/ ) { $value = 'http://' . $value; } diff --git a/t/db_dependent/Context.t b/t/db_dependent/Context.t index b5a050faf6..bce0cef209 100755 --- a/t/db_dependent/Context.t +++ b/t/db_dependent/Context.t @@ -39,6 +39,10 @@ C4::Context->clear_syspref_cache(); $OPACBaseURL = C4::Context->preference('OPACBaseURL'); is($OPACBaseURL,'http://junk2','OPACBaseURL saved with http:// as specified'); +C4::Context->set_preference('OPACBaseURL', ''); +$OPACBaseURL = C4::Context->preference('OPACBaseURL'); +is($OPACBaseURL,'','OPACBaseURL saved empty as specified'); + C4::Context->set_preference('SillyPreference','random'); C4::Context->clear_syspref_cache(); my $SillyPeference = C4::Context->preference('SillyPreference'); -- 2.39.5