aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2021-11-16 18:49:37 +0100
committerGitHub <noreply@github.com>2021-11-16 18:49:37 +0100
commit67ff36bd0cc70ecb4650c8449d6d5174b5c660ab (patch)
tree38adffaf7751670aef33900a83aba8fbb72e919e /lib
parent6ea81dd2cbfb8a9013895d07fb4df17b8df27348 (diff)
parent6fc86943244e8acc88a0f742a5f406adb100ee1a (diff)
downloadnextcloud-server-67ff36bd0cc70ecb4650c8449d6d5174b5c660ab.tar.gz
nextcloud-server-67ff36bd0cc70ecb4650c8449d6d5174b5c660ab.zip
Merge pull request #29695 from YoitoFes/fix_missing_setlocale
Fix missing setlocale with php 8
Diffstat (limited to 'lib')
-rw-r--r--lib/private/legacy/OC_Util.php28
1 files changed, 22 insertions, 6 deletions
diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php
index 35c81dd34e6..078e3cf9a03 100644
--- a/lib/private/legacy/OC_Util.php
+++ b/lib/private/legacy/OC_Util.php
@@ -1239,22 +1239,38 @@ class OC_Util {
}
/**
- * Check if the setlocal call does not work. This can happen if the right
+ * Check if current locale is non-UTF8
+ *
+ * @return bool
+ */
+ private static function isNonUTF8Locale() {
+ if (function_exists('escapeshellcmd')) {
+ return '' === escapeshellcmd('§');
+ } elseif (function_exists('escapeshellarg')) {
+ return '\'\'' === escapeshellarg('§');
+ } else {
+ return 0 === preg_match('/utf-?8/i', setlocale(LC_CTYPE, 0));
+ }
+ }
+
+ /**
+ * Check if the setlocale call does not work. This can happen if the right
* local packages are not available on the server.
*
* @return bool
*/
public static function isSetLocaleWorking() {
- if ('' === basename('§')) {
+ if (self::isNonUTF8Locale()) {
// 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('§')) {
- return false;
+ // Check again
+ if (self::isNonUTF8Locale()) {
+ return false;
+ }
}
+
return true;
}