]> granicus.if.org Git - php/commitdiff
fixed shift_jis character corruption including 0x5c as second byte on uploaded filename.
authorRui Hirokawa <hirokawa@php.net>
Wed, 3 Jul 2002 13:36:19 +0000 (13:36 +0000)
committerRui Hirokawa <hirokawa@php.net>
Wed, 3 Jul 2002 13:36:19 +0000 (13:36 +0000)
ext/mbstring/mbstring.c
ext/mbstring/mbstring.h
main/rfc1867.c

index 90d8a9d8c8e6c6606cabc4c529967526041c4b46..ae43455e7db0b5945ceaee674c282ff26618cea3 100644 (file)
@@ -1323,6 +1323,27 @@ SAPI_POST_HANDLER_FUNC(php_mbstr_post_handler)
 }
 #endif
 
+
+#define IS_SJIS1(c) ((((c)>=0x81 && (c)<=0x9f) || ((c)>=0xe0 && (c)<=0xf5)) ? 1 : 0)
+#define IS_SJIS2(c) ((((c)>=0x40 && (c)<=0x7e) || ((c)>=0x80 && (c)<=0xfc)) ? 1 : 0)
+
+char *mbstr_strrchr(const char *s, char c){
+       unsigned char *p = (unsigned char *)s, *last = NULL;
+       while(*p++) {
+               if (*p == c) {
+                       last = p;
+               }
+               if (*p == '\0'){
+                       break;
+               }
+               if (MBSTRG(current_language) == mbfl_no_language_japanese 
+                       && IS_SJIS1(*p) && IS_SJIS2(*(p+1))) {
+                       p++;
+               }
+       }
+       return last;
+}
+
 /* http input processing */
 void mbstr_treat_data(int arg, char *str, zval* destArray TSRMLS_DC)
 {
index 98623e77b49878c33366d78d55857db783f0d39b..91175f842141364ebcf518e57f135931a42d5cab 100644 (file)
@@ -124,6 +124,8 @@ PHP_FUNCTION(mb_ereg_search_setpos);
 int php_mbregex_name2mbctype(const char *pname);
 #endif
 
+char *mbstr_strrchr(const char *s, char c);
+
 ZEND_BEGIN_MODULE_GLOBALS(mbstring)
        int language;
        int current_language;
index 549ffa4d768a8202b053fc1c88a3a16575e8a240..a5984830eda2e4e37973f32f8ffa66fd5fc8ed72 100644 (file)
@@ -32,6 +32,9 @@
 #include "php_variables.h"
 #include "rfc1867.h"
 
+#if HAVE_MBSTRING
+#include "ext/mbstring/mbstring.h"
+#endif
 
 #undef DEBUG_FILE_UPLOAD
 
@@ -823,7 +826,11 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
                                sprintf(lbuf, "%s_name", param);
                        }
 
+#if HAVE_MBSTRING
+                       s = mbstr_strrchr(filename, '\\');
+#else
                        s = strrchr(filename, '\\');
+#endif
                        if (s && s > filename) {
                                safe_php_register_variable(lbuf, s+1, NULL, 0 TSRMLS_CC);
                        } else {