From ef4179de3a4fc11896aa64fae4b57291c2d83e1d Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Tue, 6 Apr 2021 16:26:23 +0200
Subject: [PATCH] Bug 28094: Deal with encoding for overriden sysprefs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The string we retrieved is UTF-8 encoded, to prevent encoding issue we
must decode it first.

Test plan:
Easily testable with LibraryName:
1. edit /etc/apache2/sites-available/kohadev.conf
2. Add
  RequestHeader add X-Koha-SetEnv "OVERRIDE_SYSPREF_LibraryName Library of ❤️"
3. restart_all
4. Hit the mainpage and look at the source (or title) and confirm that
the string is displayed correcty

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
---
 C4/Context.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/C4/Context.pm b/C4/Context.pm
index 06bdf08e44..01c33b438c 100644
--- a/C4/Context.pm
+++ b/C4/Context.pm
@@ -405,7 +405,7 @@ sub preference {
     my $self = shift;
     my $var  = shift;    # The system preference to return
 
-    return $ENV{"OVERRIDE_SYSPREF_$var"}
+    return Encode::decode_utf8($ENV{"OVERRIDE_SYSPREF_$var"})
         if defined $ENV{"OVERRIDE_SYSPREF_$var"};
 
     $var = lc $var;
-- 
2.20.1