Browse Source

adding hack to fix setlocale behavior on OpenBSD 3.8+ (#1427512). I don't think
that e-a-department (obsd) cares about it.

tokul 19 years ago
parent
commit
ab1caa233f
2 changed files with 17 additions and 5 deletions
  1. 1 0
      ChangeLog
  2. 16 5
      include/languages.php

+ 1 - 0
ChangeLog

@@ -43,6 +43,7 @@ Version 1.5.2 - CVS
   - Fixed automatic mailbox creation in left_main.php. 1.5.1 mailbox caching 
     broke detection of unsubscribed special folders.
   - Undo extra sanitizing in decodeHeader() function (#1460638).
+  - Added workaround for broken OpenBSD 3.8+ setlocale() function (#1427512).
 
 Version 1.5.1 (branched on 2006-02-12)
 --------------------------------------

+ 16 - 5
include/languages.php

@@ -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;
 }