Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15446750
D10555.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D10555.diff
View Options
diff --git a/src/xsprintf/PhutilCommandString.php b/src/xsprintf/PhutilCommandString.php
--- a/src/xsprintf/PhutilCommandString.php
+++ b/src/xsprintf/PhutilCommandString.php
@@ -7,6 +7,8 @@
const MODE_DEFAULT = 'default';
const MODE_POWERSHELL = 'powershell';
+ const MODE_WINDOWSCMD = 'windowscmd';
+ const MODE_BASH = 'bash';
public function __construct(array $argv) {
$this->argv = $argv;
@@ -51,6 +53,10 @@
return escapeshellarg($value);
case self::MODE_POWERSHELL:
return self::escapePowershell($value);
+ case self::MODE_WINDOWSCMD:
+ return self::escapeWindowsCMD($value);
+ case self::MODE_BASH:
+ return self::escapeBash($value);
default:
throw new Exception('Unknown escaping mode!');
}
@@ -82,4 +88,24 @@
return '"'.$value.'"';
}
+ private static function escapeWindowsCMD($value) {
+
+ // Just replace " with \". The Windows command prompt is seriously
+ // broken in terms of escaping parameters, so there's no sane way
+ // to actually escape here.
+ $value = str_replace('"', '\\"', $value);
+
+ return '"'.$value.'"';
+ }
+
+ private static function escapeBash($value) {
+
+ // We put everything in single quotes, except that you can't use single
+ // quotes at all inside a single quoted string in Bash. Instead, we change
+ // over to double quotes for single quotes.
+ $value = str_replace('\'', '\'"\'"\'', $value);
+
+ return '\''.$value.'\'';
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 28, 8:02 PM (4 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7389737
Default Alt Text
D10555.diff (1 KB)
Attached To
Mode
D10555: Implement escaping logic for Windows Command Prompt and Bash in PhutilCommandString
Attached
Detach File
Event Timeline
Log In to Comment