From: Greg Beaver Date: Sat, 25 Jul 2009 23:45:45 +0000 (+0000) Subject: more php6 fixes for phar, fix more tests X-Git-Tag: php-5.4.0alpha1~191^2~2976 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fba6dd1cbf724981c32bb513f692afe6a2c0009e;p=php more php6 fixes for phar, fix more tests --- diff --git a/ext/phar/cgidebug b/ext/phar/cgidebug index 1907581900..55ac486ddd 100755 --- a/ext/phar/cgidebug +++ b/ext/phar/cgidebug @@ -1,11 +1,11 @@ #!/bin/sh -export SCRIPT_NAME=/front.phar.php +export SCRIPT_NAME=/frontcontroller21.php export PATH_INFO=/index.php -export SCRIPT_FILENAME=/home/cellog/workspace/php5/ext/phar/tests/front.phar.php -export PATH_TRANSLATED=/home/cellog/workspace/php5/ext/phar/tests/front.phar.php +export SCRIPT_FILENAME=/home/user/workspace/phpsvn/php/php-src/trunk/ext/phar/tests/frontcontroller21.php +export PATH_TRANSLATED=/home/user/workspace/phpsvn/php/php-src/trunk/ext/phar/tests/frontcontroller21.php export REDIRECT_STATUS=1 export REQUEST_METHOD=GET -export REQUEST_URI=/front.phar.php/index.php -cd /home/cellog/workspace/php5 +export REQUEST_URI=/frontcontroller21.php/index.php?test=hi +cd /home/user/workspace/phpsvn/php/php-src/trunk/ ddd sapi/cgi/php-cgi & -cd /home/cellog/workspace/php5/ext/phar +cd /home/user/workspace/phpsvn/php/php-src/trunk/ext/phar diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 247e8e1ef8..f5b89c873b 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -56,12 +56,51 @@ static int phar_file_type(HashTable *mimes, char *file, char **mime_type TSRMLS_ } /* }}} */ +#if PHP_MAJOR_VERSION >= 6 +static inline int phar_make_unicode(zstr *c_var, char *arKey, uint nKeyLength TSRMLS_DC) +{ + int c_var_len; + UConverter *conv = ZEND_U_CONVERTER(UG(runtime_encoding_conv)); + + c_var->u = NULL; + if (zend_string_to_unicode(conv, &c_var->u, &c_var_len, arKey, nKeyLength TSRMLS_CC) == FAILURE) { + + if (c_var->u) { + efree(c_var->u); + } + return 0; + + } + return c_var_len; +} +static inline int phar_find_key(HashTable *_SERVER, char *key, int len, void **stuff TSRMLS_DC) +{ + if (SUCCESS == zend_hash_find(_SERVER, key, len, stuff)) { + return 1; + } else { + int s = len; + zstr var; + s = phar_make_unicode(&var, key, len TSRMLS_CC); + if (SUCCESS == zend_u_hash_find(_SERVER, IS_UNICODE, var, s, stuff)) { + efree(var.u); + return 1; + } + efree(var.u); + return 0; + } +} +#endif static void phar_mung_server_vars(char *fname, char *entry, int entry_len, char *basename, int request_uri_len TSRMLS_DC) /* {{{ */ { +#if PHP_MAJOR_VERSION >= 6 + int is_unicode = 0; +#endif HashTable *_SERVER; zval **stuff; char *path_info; int basename_len = strlen(basename); + int code; + zval *temp; /* "tweak" $_SERVER variables requested in earlier call to Phar::mungServer() */ if (!PG(http_globals)[TRACK_VARS_SERVER]) { @@ -71,9 +110,17 @@ static void phar_mung_server_vars(char *fname, char *entry, int entry_len, char _SERVER = Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]); /* PATH_INFO and PATH_TRANSLATED should always be munged */ +#if PHP_MAJOR_VERSION >= 6 + if (phar_find_key(_SERVER, "PATH_INFO", sizeof("PATH_INFO"), (void **) &stuff TSRMLS_CC)) { + if (Z_TYPE_PP(stuff) == IS_UNICODE) { + is_unicode = 1; + zval_unicode_to_string(*stuff TSRMLS_CC); + } else { + is_unicode = 0; + } +#else if (SUCCESS == zend_hash_find(_SERVER, "PATH_INFO", sizeof("PATH_INFO"), (void **) &stuff)) { - int code; - zval *temp; +#endif path_info = Z_STRVAL_PP(stuff); code = Z_STRLEN_PP(stuff); @@ -83,13 +130,26 @@ static void phar_mung_server_vars(char *fname, char *entry, int entry_len, char MAKE_STD_ZVAL(temp); ZVAL_STRINGL(temp, path_info, code, 0); - zend_hash_update(_SERVER, "PHAR_PATH_INFO", sizeof("PHAR_PATH_INFO"), (void *) &temp, sizeof(zval **), NULL); +#if PHP_MAJOR_VERSION >= 6 + if (is_unicode) { + zval_string_to_unicode(*stuff TSRMLS_CC); + } +#endif + zend_hash_update(_SERVER, "PHAR_PATH_INFO", sizeof("PHAR_PATH_INFO"), &temp, sizeof(zval **), NULL); } } +#if PHP_MAJOR_VERSION >= 6 + if (phar_find_key(_SERVER, "PATH_TRANSLATED", sizeof("PATH_TRANSLATED"), (void **) &stuff TSRMLS_CC)) { + if (Z_TYPE_PP(stuff) == IS_UNICODE) { + is_unicode = 1; + zval_unicode_to_string(*stuff TSRMLS_CC); + } else { + is_unicode = 0; + } +#else if (SUCCESS == zend_hash_find(_SERVER, "PATH_TRANSLATED", sizeof("PATH_TRANSLATED"), (void **) &stuff)) { - int code; - zval *temp; +#endif path_info = Z_STRVAL_PP(stuff); code = Z_STRLEN_PP(stuff); @@ -97,6 +157,11 @@ static void phar_mung_server_vars(char *fname, char *entry, int entry_len, char MAKE_STD_ZVAL(temp); ZVAL_STRINGL(temp, path_info, code, 0); +#if PHP_MAJOR_VERSION >= 6 + if (is_unicode) { + zval_string_to_unicode(*stuff TSRMLS_CC); + } +#endif zend_hash_update(_SERVER, "PHAR_PATH_TRANSLATED", sizeof("PHAR_PATH_TRANSLATED"), (void *) &temp, sizeof(zval **), NULL); } @@ -105,9 +170,17 @@ static void phar_mung_server_vars(char *fname, char *entry, int entry_len, char } if (PHAR_GLOBALS->phar_SERVER_mung_list & PHAR_MUNG_REQUEST_URI) { +#if PHP_MAJOR_VERSION >= 6 + if (phar_find_key(_SERVER, "REQUEST_URI", sizeof("REQUEST_URI"), (void **) &stuff TSRMLS_CC)) { + if (Z_TYPE_PP(stuff) == IS_UNICODE) { + is_unicode = 1; + zval_unicode_to_string(*stuff TSRMLS_CC); + } else { + is_unicode = 0; + } +#else if (SUCCESS == zend_hash_find(_SERVER, "REQUEST_URI", sizeof("REQUEST_URI"), (void **) &stuff)) { - int code; - zval *temp; +#endif path_info = Z_STRVAL_PP(stuff); code = Z_STRLEN_PP(stuff); @@ -117,15 +190,28 @@ static void phar_mung_server_vars(char *fname, char *entry, int entry_len, char MAKE_STD_ZVAL(temp); ZVAL_STRINGL(temp, path_info, code, 0); +#if PHP_MAJOR_VERSION >= 6 + if (is_unicode) { + zval_string_to_unicode(*stuff TSRMLS_CC); + } +#endif zend_hash_update(_SERVER, "PHAR_REQUEST_URI", sizeof("PHAR_REQUEST_URI"), (void *) &temp, sizeof(zval **), NULL); } } } if (PHAR_GLOBALS->phar_SERVER_mung_list & PHAR_MUNG_PHP_SELF) { +#if PHP_MAJOR_VERSION >= 6 + if (phar_find_key(_SERVER, "PHP_SELF", sizeof("PHP_SELF"), (void **) &stuff TSRMLS_CC)) { + if (Z_TYPE_PP(stuff) == IS_UNICODE) { + is_unicode = 1; + zval_unicode_to_string(*stuff TSRMLS_CC); + } else { + is_unicode = 0; + } +#else if (SUCCESS == zend_hash_find(_SERVER, "PHP_SELF", sizeof("PHP_SELF"), (void **) &stuff)) { - int code; - zval *temp; +#endif path_info = Z_STRVAL_PP(stuff); code = Z_STRLEN_PP(stuff); @@ -135,15 +221,28 @@ static void phar_mung_server_vars(char *fname, char *entry, int entry_len, char MAKE_STD_ZVAL(temp); ZVAL_STRINGL(temp, path_info, code, 0); +#if PHP_MAJOR_VERSION >= 6 + if (is_unicode) { + zval_string_to_unicode(*stuff TSRMLS_CC); + } +#endif zend_hash_update(_SERVER, "PHAR_PHP_SELF", sizeof("PHAR_PHP_SELF"), (void *) &temp, sizeof(zval **), NULL); } } } if (PHAR_GLOBALS->phar_SERVER_mung_list & PHAR_MUNG_SCRIPT_NAME) { +#if PHP_MAJOR_VERSION >= 6 + if (phar_find_key(_SERVER, "SCRIPT_NAME", sizeof("SCRIPT_NAME"), (void **) &stuff TSRMLS_CC)) { + if (Z_TYPE_PP(stuff) == IS_UNICODE) { + is_unicode = 1; + zval_unicode_to_string(*stuff TSRMLS_CC); + } else { + is_unicode = 0; + } +#else if (SUCCESS == zend_hash_find(_SERVER, "SCRIPT_NAME", sizeof("SCRIPT_NAME"), (void **) &stuff)) { - int code; - zval *temp; +#endif path_info = Z_STRVAL_PP(stuff); code = Z_STRLEN_PP(stuff); @@ -151,14 +250,27 @@ static void phar_mung_server_vars(char *fname, char *entry, int entry_len, char MAKE_STD_ZVAL(temp); ZVAL_STRINGL(temp, path_info, code, 0); +#if PHP_MAJOR_VERSION >= 6 + if (is_unicode) { + zval_string_to_unicode(*stuff TSRMLS_CC); + } +#endif zend_hash_update(_SERVER, "PHAR_SCRIPT_NAME", sizeof("PHAR_SCRIPT_NAME"), (void *) &temp, sizeof(zval **), NULL); } } if (PHAR_GLOBALS->phar_SERVER_mung_list & PHAR_MUNG_SCRIPT_FILENAME) { +#if PHP_MAJOR_VERSION >= 6 + if (phar_find_key(_SERVER, "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME"), (void **) &stuff TSRMLS_CC)) { + if (Z_TYPE_PP(stuff) == IS_UNICODE) { + is_unicode = 1; + zval_unicode_to_string(*stuff TSRMLS_CC); + } else { + is_unicode = 0; + } +#else if (SUCCESS == zend_hash_find(_SERVER, "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME"), (void **) &stuff)) { - int code; - zval *temp; +#endif path_info = Z_STRVAL_PP(stuff); code = Z_STRLEN_PP(stuff); @@ -166,6 +278,11 @@ static void phar_mung_server_vars(char *fname, char *entry, int entry_len, char MAKE_STD_ZVAL(temp); ZVAL_STRINGL(temp, path_info, code, 0); +#if PHP_MAJOR_VERSION >= 6 + if (is_unicode) { + zval_string_to_unicode(*stuff TSRMLS_CC); + } +#endif zend_hash_update(_SERVER, "PHAR_SCRIPT_FILENAME", sizeof("PHAR_SCRIPT_FILENAME"), (void *) &temp, sizeof(zval **), NULL); } } @@ -857,7 +974,23 @@ PHP_METHOD(Phar, webPhar) if (ext) { ++ext; +#if PHP_MAJOR_VERSION >= 6 + if (FAILURE == zend_hash_find(Z_ARRVAL_P(mimeoverride), ext, strlen(ext)+1, (void **) &val)) { + /* try unicode extension */ + zstr zext; + zspprintf(IS_UNICODE, &zext, 0, "%s", ext); + if (SUCCESS == zend_u_hash_find(Z_ARRVAL_P(mimeoverride), IS_UNICODE, zext, strlen(ext)+1, (void **) &val)) { + ezfree(zext); + goto unicode_found; + } + ezfree(zext); + goto notfound; + } +unicode_found: + { /* this prevents parse error */ +#else if (SUCCESS == zend_hash_find(Z_ARRVAL_P(mimeoverride), ext, strlen(ext)+1, (void **) &val)) { +#endif switch (Z_TYPE_PP(val)) { case IS_LONG: if (Z_LVAL_PP(val) == PHAR_MIME_PHP || Z_LVAL_PP(val) == PHAR_MIME_PHPS) { @@ -871,6 +1004,11 @@ PHP_METHOD(Phar, webPhar) RETURN_FALSE; } break; +#if PHP_MAJOR_VERSION >= 6 + case IS_UNICODE: + zval_unicode_to_string(*(val) TSRMLS_CC); + /* break intentionally omitted */ +#endif case IS_STRING: mime_type = Z_STRVAL_PP(val); code = PHAR_MIME_OTHER; @@ -886,6 +1024,7 @@ PHP_METHOD(Phar, webPhar) } } +notfound: if (!mime_type) { code = phar_file_type(&PHAR_G(mime_types), entry, &mime_type TSRMLS_CC); } @@ -921,12 +1060,25 @@ PHP_METHOD(Phar, mungServer) for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(mungvalues)); SUCCESS == zend_hash_has_more_elements(Z_ARRVAL_P(mungvalues)); zend_hash_move_forward(Z_ARRVAL_P(mungvalues))) { zval **data = NULL; +#if PHP_MAJOR_VERSION >= 6 + zval *unicopy = NULL; +#endif if (SUCCESS != zend_hash_get_current_data(Z_ARRVAL_P(mungvalues), (void **) &data)) { zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "unable to retrieve array value in Phar::mungServer()"); return; } +#if PHP_MAJOR_VERSION >= 6 + if (Z_TYPE_PP(data) == IS_UNICODE) { + MAKE_STD_ZVAL(unicopy); + *unicopy = **data; + zval_copy_ctor(unicopy); + zval_unicode_to_string(unicopy TSRMLS_CC); + data = &unicopy; + } +#endif + if (Z_TYPE_PP(data) != IS_STRING) { zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Non-string value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME"); return; @@ -948,6 +1100,11 @@ PHP_METHOD(Phar, mungServer) if (Z_STRLEN_PP(data) == sizeof("SCRIPT_FILENAME")-1 && !strncmp(Z_STRVAL_PP(data), "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME")-1)) { PHAR_GLOBALS->phar_SERVER_mung_list |= PHAR_MUNG_SCRIPT_FILENAME; } +#if PHP_MAJOR_VERSION >= 6 + if (unicopy) { + zval_ptr_dtor(&unicopy); + } +#endif } } /* }}} */ diff --git a/ext/phar/tests/files/frontcontroller12.phar b/ext/phar/tests/files/frontcontroller12.phar index 9e45587610..315c2901e0 100644 Binary files a/ext/phar/tests/files/frontcontroller12.phar and b/ext/phar/tests/files/frontcontroller12.phar differ diff --git a/ext/phar/tests/files/frontcontroller12.phar.inc b/ext/phar/tests/files/frontcontroller12.phar.inc index ba17df37e1..f1e4645e2f 100644 --- a/ext/phar/tests/files/frontcontroller12.phar.inc +++ b/ext/phar/tests/files/frontcontroller12.phar.inc @@ -3,13 +3,13 @@ $a = new Phar(dirname(__FILE__) . '/frontcontroller12.phar'); $a['index.php'] = 'setStub('setStub('setStub(' false); + static $b = array(b"/hi" => false); if (isset($b[$a])) return $b[$a]; return $a; } diff --git a/ext/phar/tests/fopen_edgecases2U.phpt b/ext/phar/tests/fopen_edgecases2U.phpt new file mode 100644 index 0000000000..09c7b00570 --- /dev/null +++ b/ext/phar/tests/fopen_edgecases2U.phpt @@ -0,0 +1,46 @@ +--TEST-- +Phar: test edge cases of fopen() function interception #2 (PHP 6) +--SKIPIF-- + + +--INI-- +phar.readonly=0 +--FILE-- + +'); +include $pname . '/foo/hi'; +?> +===DONE=== +--CLEAN-- + + + +--EXPECTF-- +Notice: Array to string conversion in %sfopen_edgecases2U.php on line 6 + +Warning: fopen(Array): failed to open stream: No such file or directory in %sfopen_edgecases2U.php on line 6 +blah +test + +Warning: fopen(phar://%sfopen_edgecases2U.phar.php/oops): failed to open stream: phar error: path "oops" is a directory in phar://%sfopen_edgecases2U.phar.php/foo/hi on line 6 +===DONE=== \ No newline at end of file diff --git a/ext/phar/tests/frontcontroller21.phpt b/ext/phar/tests/frontcontroller21.phpt index dcdbf575fe..bf50c6e801 100644 --- a/ext/phar/tests/frontcontroller21.phpt +++ b/ext/phar/tests/frontcontroller21.phpt @@ -14,7 +14,7 @@ files/frontcontroller12.phar --EXPECTHEADERS-- Content-type: text/html; charset=UTF-8 --EXPECTF-- -string(10) "/index.php" +%unicode|string%(10) "/index.php" string(10) "/index.php" string(%d) "phar://%sfrontcontroller21.php/index.php" string(18) "/index.php?test=hi" diff --git a/ext/phar/tests/frontcontroller22.phpt b/ext/phar/tests/frontcontroller22.phpt index 827c5688c7..b85c1eb497 100644 --- a/ext/phar/tests/frontcontroller22.phpt +++ b/ext/phar/tests/frontcontroller22.phpt @@ -13,8 +13,8 @@ files/frontcontroller13.phar --EXPECTHEADERS-- Content-type: text/html; charset=UTF-8 --EXPECTF-- -string(4) "test" -string(12) "oof/test.php" +%unicode|string%(4) "test" +%unicode|string%(12) "oof/test.php" Warning: include(./hi.php): failed to open stream: No such file or directory in phar://%s/oof/test.php on line %d