From: Xinchen Hui Date: Tue, 1 Nov 2011 12:24:02 +0000 (+0000) Subject: Fixed Bug #60180 ($_SERVER["PHP_SELF"] incorrect) X-Git-Tag: php-5.4.0RC1~51 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ac789e0bb6d7963c0bbb28229c601d944e33bcea;p=php Fixed Bug #60180 ($_SERVER["PHP_SELF"] incorrect) --- diff --git a/NEWS b/NEWS index 02a1ce9ae1..67fee7d25c 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,7 @@ PHP NEWS (Laruence) . Fixed bug #60115 (memory definitely lost in cli server). (Laruence) . Fixed bug #60146 (Last 2 lines of page not being output). (Laruence) + . Fixed bug #60180 ($_SERVER["PHP_SELF"] incorrect). (Laruence) - Core: . Fixed bug #60120 (proc_open's streams may hang with stdin/out/err when diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 046c622e55..67df608672 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -579,13 +579,21 @@ static void sapi_cli_server_register_variables(zval *track_vars_array TSRMLS_DC) } sapi_cli_server_register_variable(track_vars_array, "REQUEST_URI", client->request.request_uri TSRMLS_CC); sapi_cli_server_register_variable(track_vars_array, "REQUEST_METHOD", SG(request_info).request_method TSRMLS_CC); - sapi_cli_server_register_variable(track_vars_array, "PHP_SELF", client->request.vpath TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "SCRIPT_NAME", client->request.vpath TSRMLS_CC); if (SG(request_info).path_translated) { sapi_cli_server_register_variable(track_vars_array, "SCRIPT_FILENAME", SG(request_info).path_translated TSRMLS_CC); } if (client->request.path_info) { sapi_cli_server_register_variable(track_vars_array, "PATH_INFO", client->request.path_info TSRMLS_CC); } + if (client->request.path_info_len) { + char *tmp; + spprintf(&tmp, 0, "%s%s", client->request.vpath, client->request.path_info); + sapi_cli_server_register_variable(track_vars_array, "PHP_SELF", tmp TSRMLS_CC); + efree(tmp); + } else { + sapi_cli_server_register_variable(track_vars_array, "PHP_SELF", client->request.vpath TSRMLS_CC); + } if (client->request.query_string) { sapi_cli_server_register_variable(track_vars_array, "QUERY_STRING", client->request.query_string TSRMLS_CC); } @@ -1330,6 +1338,16 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque request->path_translated = buf; request->path_translated_len = q - buf; } +#ifdef PHP_WIN32 + { + uint i = 0; + for (;ivpath_len;i++) { + if (request->vpath[i] == '\\') { + request->vpath[i] = '/'; + } + } + } +#endif request->sb = sb; } /* }}} */ diff --git a/sapi/cli/tests/php_cli_server_010.phpt b/sapi/cli/tests/php_cli_server_010.phpt new file mode 100644 index 0000000000..17bfb3863b --- /dev/null +++ b/sapi/cli/tests/php_cli_server_010.phpt @@ -0,0 +1,75 @@ +--TEST-- +Bug #60180 ($_SERVER["PHP_SELF"] incorrect) +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +HTTP/1.1 200 OK +Host: %s +Connection: closed +X-Powered-By: PHP/%s +Content-type: text/html + +string(18) "/index.php/foo/bar" +string(10) "/index.php" +string(8) "/foo/bar" +string(7) "foo=bar" +HTTP/1.0 200 OK +Host: %s +Connection: closed +X-Powered-By: PHP/%s +Content-type: text/html + +string(19) "/index.php/foo/bar/" +string(10) "/index.php" +string(9) "/foo/bar/" +string(7) "foo=bar"