PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » PEAR » PEAR_PackageFileManager » Bug #3696

PHP SAPI check in debugPackageFile() not reliable, use php_sapi_name() instead

Details

Submitted2005-03-03 22:38 UTC
Frommichaels at crye-leike dot com
Assignedcellog
StatusClosed
PackagePEAR_PackageFileManager
PHP Version5.0.3
OSLinux
Roadmaps(Not assigned)

Comments

[2005-03-03 22:38 UTC] michaels at crye-leike dot com

Description:
------------
Using PEAR_PackageFileManager 1.4.0

PHP 5.0.3 configured with:
./configure --with-mysql=/usr --with-pgsql=/usr --with-sybase-ct=/usr/local --with-zlib --with-apxs=/usr/bin/apxs --enable-memory-limit --with-xsl

PEAR_PackageFileManager::debugPackageFile() uses
isset($_SERVER['PATH_TRANSLATED']) to determine if the current SAPI is a webserver or the CLI. However, on my installation $_SERVER['PATH_TRANSLATED'] is set even for CLI scripts (when ran from a shell script with a shabang line and the executable bit set). It seems that:

$webinterface = (php_sapi_name() != 'cli');

is better than

$webinterface = isset($_SERVER['PATH_TRANSLATED']);

(line 995 of PackageFileManager.php)

Reproduce code:
---------------
#!/usr/local/bin/php
<?
require_once'PEAR/PackageFileManager.php';

$packagexml = new PEAR_PackageFileManager;
$packagexml->setOptions(array(
'package' => 'MyPackage',
'summary' => 'This is a test summary',
'description' => 'This is a test description',
'version' => '1.0.0',
'state' => 'stable',
'baseinstalldir' => '/',
'packagedirectory' => dirname(__FILE__)
));
$packagexml->addMaintainer('example', 'lead', 'Lead Dev', 'user@example.com');
//unset($_SERVER['PATH_TRANSLATED']); //Uncomment this line to work around problem
$packagexml->debugPackageFile();
?>

Expected result:
----------------
Standard XML document written to stdout without <pre> tags and without htmlentities() escaping

Actual result:
--------------
XML document written to stdout surrounded by <pre> tags and with xml content processed via htmlentities()