|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #40928 escapeshellarg() does not quote percent (%) correctly for cmd.exe
Submitted: 2007-03-27 13:31 UTC Modified: 2008-08-10 01:00 UTC
Avg. Score:5.0 ± 0.0
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:2 (40.0%)
From: phpbug dot 40928 at sub dot noloop dot net Assigned:
Status: No Feedback Package: Feature/Change Request
PHP Version: 5.2.1 OS: Windows Server 2003
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-03-27 13:31 UTC] phpbug dot 40928 at sub dot noloop dot net
On win32, the function escapeshellarg() replaces percent characters (%) with spaces. Instead, the function should escape the percent character, perhaps using the ^% construct, so that the percent sign can be safely used as a an argument to an application executed through exec().

Reproduce code:

  // .... This creates a directory called "Test dir"  (without the quotes)
  // .... which is unexpected.
  $cmd = 'md';
  $arg = 'test%dir';
  $fullcmd = $cmd.' '.escapeshellarg($arg);

  // .... This creates a directory called "Test%dir"  (without the quotes)
  // .... which is the expected result of the above.
  // $fullcmd = 'md test^%dir';

  system("dir /B");


Expected result:

Actual result:
test dir


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-29 11:56 UTC] phpbug dot 40928 at sub dot noloop dot net
Changing email, please ignore this comment.
 [2008-08-02 19:22 UTC]
Please test out 5.3 in which bug #43261 was fixed that uses the ^ escape character on Windows:
 [2008-08-10 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 11:01:25 2019 UTC