Menu

#76 Controller bug when using PHP as CGI

open
nobody
5
2005-03-04
2005-03-04
Kirk Ismay
No

I've found a bug or two in the WACT controller class
when its run under PHP 4.3.10 as a CGI.

First, since the getRealPath function uses
$_SERVER['SCRIPT_NAME'], the html:link tag does not
produce the correct link, as $_SERVER['SCRIPT_NAME'] is
set to /cgi-bin/php. The following patch fixes the
html:link problem:

Index: controller.inc.php

RCS file:
/cvsroot/wact/wact/framework/controller/controller.inc.php,v
retrieving revision 1.20
diff -u -r1.20 controller.inc.php
--- controller.inc.php 25 Feb 2005 17:33:59 -0000
1.20
+++ controller.inc.php 1 Mar 2005 22:06:58 -0000
@@ -249,7 +249,12 @@
$Path = '';
$this->_buildRealPath($Path, $parameters,
$virtualPath);

- $realPath = $_SERVER['SCRIPT_NAME'];
+ if (php_sapi_name() == 'cgi') {
+ /* As a cgi, SCRIPT_NAME is /cgi-bin/php */
+ $realPath = $_SERVER['PATH_INFO'];
+ } else {
+ $realPath = $_SERVER['SCRIPT_NAME'];
+ }
if (!empty($Path)) {
$realPath .= '/' . $Path;
}
@@ -429,4 +434,4 @@

}

The patch (above) uses PATH_INFO, since it is defined
by the CGI/1.1 spec, and should work systems other than
Apache. This patch breaks the test cases for
controllers, which also use $_SERVER['SCRIPT_NAME'].
This can be fixed by using the setUp() function of the
test case like this:

function setUp() {
if (php_sapi_name() == 'cgi') {
/* As a cgi, SCRIPT_NAME is /cgi-bin/php */
$this->ScriptURI = $_SERVER['PATH_INFO'];
} else {
$this->ScriptURI = $_SERVER['SCRIPT_NAME'];
}
}

function testGetRealPathUri() {
$controller =& new PathInfoDispatchController(
array(
'index' => 'Blah',
'test' => 'Blah'),
'index');

$expectedPath = $this->ScriptURI . '/test';
$this->assertEqual($expectedPath,
$controller->getRealPath('/test'));
}

I'm willing to modify the test cases too, if desired.

Discussion


Log in to post a comment.