Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix missing setlocale with php 8
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 <[email protected]>
  • Loading branch information
YoitoFes authored and backportbot[bot] committed Nov 17, 2021
commit d5cff00d1042c557e034ae9c80aac1b2f35076d9
4 changes: 2 additions & 2 deletions lib/private/legacy/OC_Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -1280,14 +1280,14 @@ public function isHtaccessWorking(\OCP\IConfig $config) {
* @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;
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public function testEncodePath() {
$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());
Expand Down