PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Console » Console_Getopt » Bug #4448

Long parameter values truncated with longoption parameter

Details

Submitted2005-05-26 21:24 UTC
Fromdang dot nguyen at docusign dot com
Assignedandrei
StatusClosed
PackageConsole_Getopt
PHP Version5.0.4
OSWindows XP Pro
Roadmaps(Not assigned)

Comments

[2005-05-26 21:24 UTC] dang dot nguyen at docusign dot com

Description:
------------
When using the longoption parameter for getopt(), long values get truncated. The same values, if passed in by shortoption parameter, do not get truncated.

CLI example:

php myscript.php --xml="http://test.docusign.net/Member/EmailStart.aspx?a=a9340ac9-f2b0-4eb8-a9f1-09c48d950d60"
-x"http://test.docusign.net/Member/EmailStart.aspx?a=a9340ac9-f2b0-4eb8-a9f1-09c48d950d60"

Environment:
Console::GetOpt version 1.2
PHP 5.0.4
Apache 2.0 on Windows XP Pro

Reproduce code:
---------------
<?
require_once 'Console/Getopt.php';

$shortoptions = 'x';
$longoptions = array('xml=');
$console = new Console_Getopt;
$args = $console->readPHPargv();
$ret = $console->getopt($args, $shortoptions, $longoptions);

print_r($ret[0]);
?>

Expected result:
----------------
$ret[0][0][1] should equal $ret[0][1][1], but it is truncated.

Actual result:
--------------
The parameter value when specified in a "longoption" gets truncated while the parameter value specified in a "shortoption" does not.

[2006-03-10 12:52 UTC] neuhauser+bugs dot php dot net at sigpipe dot cz

the problem is the "=" in the query string.

Console/Getopt.php needs this patch (will end up mutilated by the form, watch out!):

Index: Console/Getopt.php
===================================================================
RCS file: /repository/pear-core/Console/Getopt.php,v
retrieving revision 1.28
diff -u -r1.28 Getopt.php
--- Console/Getopt.php 8 Jan 2004 17:33:10 -0000 1.28
+++ Console/Getopt.php 10 Mar 2006 12:44:37 -0000
@@ -184,7 +184,7 @@
*/
function _parseLongOption($arg, $long_options, &$opts, &$args)
{
- @list($opt, $opt_arg) = explode('=', $arg);
+ @list($opt, $opt_arg) = explode('=', $arg, 2);
$opt_len = strlen($opt);

for ($i = 0; $i < count($long_options); $i++) {