From e9c6de5c79c486ff1af3c1ed853dd1302a758270 Mon Sep 17 00:00:00 2001 From: Naoto Kobayashi Date: Sun, 14 Nov 2021 00:58:36 +0900 Subject: [PATCH] Fix missing setlocale with php 8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When php version = 8, basename('§') does not bug even if LC_ALL is non-UTF-8 locale. This cause OC_Util::isSetLocaleWorking() to skip setlocale("C.UTF-8"). Fix it by using escapeshellcmd instead of basename. Signed-off-by: Naoto Kobayashi --- lib/private/legacy/OC_Util.php | 4 ++-- tests/lib/UtilTest.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index f1e88166e97..1a029e9006f 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -1298,14 +1298,14 @@ class OC_Util { * @return bool */ public static function isSetLocaleWorking() { - if ('' === basename('§')) { + if ('' === escapeshellcmd('§')) { // Borrowed from \Patchwork\Utf8\Bootup::initLocale setlocale(LC_ALL, 'C.UTF-8', 'C'); setlocale(LC_CTYPE, 'en_US.UTF-8', 'fr_FR.UTF-8', 'es_ES.UTF-8', 'de_DE.UTF-8', 'ru_RU.UTF-8', 'pt_BR.UTF-8', 'it_IT.UTF-8', 'ja_JP.UTF-8', 'zh_CN.UTF-8', '0'); } // Check again - if ('' === basename('§')) { + if ('' === escapeshellcmd('§')) { return false; } return true; diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php index 6e25ce16e75..bcabf7a7e6f 100644 --- a/tests/lib/UtilTest.php +++ b/tests/lib/UtilTest.php @@ -77,6 +77,14 @@ class UtilTest extends \Test\TestCase { $this->assertEquals("/%C2%A7%23%40test%25%26%5E%C3%A4/-child", $result); } + public function testIsSetLocaleWorking() { + // OC_Util::isSetLocaleWorking() assumes escapeshellcmd('§') returns '' with non-UTF-8 locale. + $locale = setlocale(LC_CTYPE, 0); + setlocale(LC_CTYPE, 'C'); + $this->assertEquals('', escapeshellcmd('§')); + setlocale(LC_CTYPE, $locale); + } + public function testFileInfoLoaded() { $expected = function_exists('finfo_open'); $this->assertEquals($expected, \OC_Util::fileInfoLoaded());