php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23927 System::_parseArgv() fails if there are spaces
Submitted: 2003-05-31 14:17 UTC Modified: 2003-07-28 17:52 UTC
From: greg at chiaraquartet dot net Assigned:
Status: Not a bug Package: PEAR related
PHP Version: 4.3.2 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: greg at chiaraquartet dot net
New email:
PHP Version: OS:

 

 [2003-05-31 14:17 UTC] greg at chiaraquartet dot net
the Pear packager attempts to mktemp a directory as a subdirectory of the current directory.  If the current directory has any spaces in its name (I have C:\Web Pages), then it will fail.

This is because System::mktemp is called with "-t C:\Web Pages -d"  _parseArgv's use of a regexp parses the result into "-t C:\Web" and "Pages -d"

A better command-line parsing algorithm is in phpDocumentor's Io class, it allows spaces and simply recognizes the command-line params.

Greg

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-31 16:27 UTC] greg at chiaraquartet dot net
A fix allows quoted arguments, so it would be called with

-t "C:\Web Pages" -d and expand properly.

Here is the diff with System.php:
64a65,93
>             $newargv = array();
>             $in_quote = false;
>             $index = 0;
>             foreach($argv as $arg)
>             {
>                 if (!isset($newargv[$index])) {
>                     $newargv[$index] = '';
>                 }
>                 // combine quoted values into 1 string
>                 if (!$in_quote && $arg{0} == '"') {
>                     $newargv[$index] = substr($arg,1);
>                     $in_quote = true;
>                 } elseif ($in_quote && $arg{strlen($arg) - 1} == '"') {
>                     $arg = ' ' . $arg;
>                     $newargv[$index] .= substr($arg,0,strlen($arg) - 1);
>                     $in_quote = false;
>                     $index++;
>                 } else {
>                     if ($in_quote) {
>                         $arg .= ' ';
>                     }
>                     $newargv[$index] .= $arg;
>                     if (!$in_quote) {
>                         // go to next value if not in a quote
>                         $index++;
>                     }
>                 }
>             }
>             $argv = $newargv;

and the diff against Packager.php:

119c119
<         if (!($tmpdir = System::mktemp('-t '.getcwd().' -d'))) {
---
>         if (!($tmpdir = System::mktemp('-t "'.getcwd().'" -d'))) {
 [2003-05-31 17:34 UTC] greg at chiaraquartet dot net
In addition, line 382 of System.php (in System::mktemp()) needs to be:

        if (!System::mkDir("-p \"$tmpdir\"")) {

instead of

        if (!System::mkDir("-p $tmpdir")) {

after the last applied patch
 [2003-06-03 12:28 UTC] pajoye@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the existing bug instead.

Thank you for your interest in PHP.

Spaces are currently not allowed in path, you may use the short names under win32 (c:/progra~1).

There is BC issue to take care about this problem.

btw, System::_parseArgv() is a private method, I hope you do not rely on it :)

pierre

 [2003-06-03 12:37 UTC] greg at chiaraquartet dot net
this is not a bug in path, and is not a duplicate bug.  Please read more carefully.

this is a bug in command-line options.  if you want to pass a value to a command-line option that has spaces in it, you can't.  This is a valid bug.

Please don't close this one.  The PEAR packager is calling mktemp with the value returned from getting the cwd.  Windows returns cwd with spaces in the pathname if they are there, you can complain to the authors of get_cwd about that, but it is the way PHP is written.  I posted a fix that allows quoted attributes to be passed to _argv, it doesn't break BC, and fixes the problem, why mark this as bogus?
 [2003-07-27 05:52 UTC] arnaud@php.net
what is preventing this patch from being applied ? It looks reasonnable to allow spaces in paths under windows.
 [2003-07-28 17:52 UTC] cellog@php.net
_parseArgv works if you pass it an array split along the correct places
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Feb 21 16:01:27 2020 UTC