adding hack to fix setlocale behavior on OpenBSD 3.8+ (#1427512). I don't think
[squirrelmail.git] / include / languages.php
index 342b9336af15c1cfeb299c036017d61004a64eb8..97eeb095a30b69ca575e2100e28605b39c3c7af2 100644 (file)
@@ -72,11 +72,11 @@ function sq_textdomain($domain) {
  * @see http://www.php.net/setlocale
  */
 function sq_setlocale($category,$locale) {
-    // string with only one locale
-    if (is_string($locale))
-        return setlocale($category,$locale);
-
-    if (! check_php_version(4,3)) {
+    if (is_string($locale)) {
+        // string with only one locale
+        $ret = setlocale($category,$locale);
+    } elseif (! check_php_version(4,3)) {
+        // older php version (second setlocale argument must be string)
         $ret=false;
         $index=0;
         while ( ! $ret && $index<count($locale)) {
@@ -87,6 +87,17 @@ function sq_setlocale($category,$locale) {
         // php 4.3.0 or better, use entire array
         $ret=setlocale($category,$locale);
     }
+
+    /* safety checks */
+    if (preg_match("/^.*\/.*\/.*\/.*\/.*\/.*$/",$ret)) {
+        /**
+         * Welcome to We-Don't-Follow-Own-Fine-Manual department
+         * OpenBSD 3.8, 3.9-current and maybe later versions 
+         * return invalid response to setlocale command.
+         * SM bug report #1427512.
+         */
+        $ret = false;
+    }
     return $ret;
 }