]> granicus.if.org Git - php/commitdiff
Add test for escapeshellcmd and restore previous behaviour with stripping % on Windows.
authorScott MacVicar <scottmac@php.net>
Tue, 22 Jul 2008 16:18:37 +0000 (16:18 +0000)
committerScott MacVicar <scottmac@php.net>
Tue, 22 Jul 2008 16:18:37 +0000 (16:18 +0000)
ext/standard/exec.c
ext/standard/tests/general_functions/escapeshellcmd-win32.phpt [new file with mode: 0644]

index f085fc68aa52186f074674c3bef5cc6cd7af4f58..6cf33a7493981f180029570bb6647f024b7ff049 100644 (file)
@@ -284,6 +284,11 @@ PHPAPI char *php_escape_shell_cmd(char *str)
                                }
                                cmd[y++] = str[x];
                                break;
+#else
+                       /* This is Windows specific for enviromental variables */
+                       case '%':
+                               cmd[y++] = '';
+                               break;
 #endif
                        case '#': /* This is character-set independent */
                        case '&':
@@ -307,8 +312,6 @@ PHPAPI char *php_escape_shell_cmd(char *str)
                        case '\x0A': /* excluding these two */
                        case '\xFF':
 #ifdef PHP_WIN32
-                       /* This is Windows specific for enviromental variables */
-                       case '%':
                                cmd[y++] = '^';
 #else
                                cmd[y++] = '\\';
diff --git a/ext/standard/tests/general_functions/escapeshellcmd-win32.phpt b/ext/standard/tests/general_functions/escapeshellcmd-win32.phpt
new file mode 100644 (file)
index 0000000..3da43e1
--- /dev/null
@@ -0,0 +1,46 @@
+--TEST--
+Test escapeshellcmd() functionality on Windows
+--SKIPIF--
+<?php
+if( substr(PHP_OS, 0, 3) != 'WIN' ) {
+   die('skip...Valid for Windows only');
+}
+?>
+--FILE--
+<?php
+echo "*** Testing escapeshellcmd() basic operations ***\n";
+$data = array(
+       '"abc',
+       "'abc",
+       '?<>',
+       '()[]{}$',
+       '%^',
+       '#&;`|*?',
+       '~<>\\'
+);
+
+$count = 1;
+foreach ($data AS $value) {
+       echo "-- Test " . $count++ . " --\n";
+       var_dump(escapeshellcmd($value));
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing escapeshellcmd() basic operations ***
+-- Test 1 --
+string(5) "^"abc"
+-- Test 2 --
+string(5) "^'abc"
+-- Test 3 --
+string(6) "^?^<^>"
+-- Test 4 --
+string(14) "^(^)^[^]^{^}^$"
+-- Test 5 --
+string(2) "^^"
+-- Test 6 --
+string(14) "^#^&^;^`^|^*^?"
+-- Test 7 --
+string(8) "^~^<^>^\"
+Done