Skip to content

Commit

Permalink
Fixed Bug #60180 ($_SERVER["PHP_SELF"] incorrect)
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Nov 1, 2011
1 parent 58a134f commit ac789e0
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion sapi/cli/php_cli_server.c
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 (;i<request->vpath_len;i++) {
if (request->vpath[i] == '\\') {
request->vpath[i] = '/';
}
}
}
#endif
request->sb = sb;
} /* }}} */

Expand Down
75 changes: 75 additions & 0 deletions sapi/cli/tests/php_cli_server_010.phpt
@@ -0,0 +1,75 @@
--TEST--
Bug #60180 ($_SERVER["PHP_SELF"] incorrect)
--SKIPIF--
<?php
include "skipif.inc";
?>
--FILE--
<?php
include "php_cli_server.inc";
php_cli_server_start('var_dump($_SERVER["PHP_SELF"], $_SERVER["SCRIPT_NAME"], $_SERVER["PATH_INFO"], $_SERVER["QUERY_STRING"]);', TRUE);

list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
$port = intval($port)?:80;

$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
if (!$fp) {
die("connect failed");
}

if(fwrite($fp, <<<HEADER
GET /foo/bar?foo=bar HTTP/1.1
Host: {$host}
HEADER
)) {
while (!feof($fp)) {
echo fgets($fp);
}
}

fclose($fp);

$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
if (!$fp) {
die("connect failed");
}


if(fwrite($fp, <<<HEADER
GET /index.php/foo/bar/?foo=bar HTTP/1.0
Host: {$host}
HEADER
)) {
while (!feof($fp)) {
echo fgets($fp);
}
}

fclose($fp);

?>
--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"

0 comments on commit ac789e0

Please sign in to comment.