From: RQuadling at GMail dot com
Operating system: Windows XP SP2
PHP version: 5.3CVS-2007-11-12 (snap)
PHP Bug Type: Feature/Change Request
Bug description: Use ^ as escape char for windows escapeshellcmd
Description:
------------
The windows version of escapeshellcmd replaces any of the special
characters with a space, whereas, on other platforms it escapes them.
There is a valid escape character for windows. It is the ^ character.
Taking the current set of type-able characters from exec.c, the following
is a proof of the ^ working ...
2007/11/12 13:22:42 V:\PHP\PHP5>echo foo ^' bar
foo ' bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^" bar
foo " bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^# bar
foo # bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^$ bar
foo $ bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^% bar
foo % bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^& bar
foo & bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^( bar
foo ( bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^) bar
foo ) bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^* bar
foo * bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^; bar
foo ; bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^? bar
foo ? bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^[ bar
foo [ bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^\ bar
foo \ bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^] bar
foo ] bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^^ bar
foo ^ bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^` bar
foo ` bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^{ bar
foo { bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^| bar
foo | bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^} bar
foo } bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^~ bar
foo ~ bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^< bar
foo < bar
2007/11/12 13:22:43 V:\PHP\PHP5>echo foo ^> bar
foo > bar
I can't easily emulate 0xA0 and 0xFF in this test.
I've included a patch also ...
Index: exec.c
===================================================================
RCS file: /repository/php-src/ext/standard/exec.c,v
retrieving revision 1.125
diff -u -r1.125 exec.c
--- exec.c 5 Nov 2007 14:06:19 -0000 1.125
+++ exec.c 12 Nov 2007 13:13:09 -0000
@@ -291,13 +291,12 @@
case '\\':
case '\x0A': /* excluding these two */
case '\xFF':
-#ifdef PHP_WIN32
- /* since Windows does not allow us to escape these
chars, just remove
them */
case '%':
- cmd[y++] = ' ';
- break;
-#endif
+#ifdef PHP_WIN32
+ cmd[y++] = '^';
+#else
cmd[y++] = '\\';
+#endif
/* fall-through */
default:
cmd[y++] = str[x];
http://rquadling.php1h.com/exec.c.patch.txt
Reproduce code:
---------------
php -r "exec(escapeshellcmd('echo foo | bar'), $a, $b); var_dump($a,
$b);"
Expected result:
----------------
array(1) {
[0]=>
string(10) "foo ^| bar"
}
int(0)
Actual result:
--------------
array(1) {
[0]=>
string(9) "foo bar"
}
int(0)
--
Edit bug report at http://bugs.php.net/?id=43261&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=43261&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=43261&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=43261&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=43261&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=43261&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=43261&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=43261&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=43261&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=43261&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=43261&r=support
Expected behavior: http://bugs.php.net/fix.php?id=43261&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=43261&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=43261&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=43261&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43261&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=43261&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=43261&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=43261&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=43261&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=43261&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=43261&r=mysqlcfg