Page MenuHomePhabricator

D10555.diff
No OneTemporary

D10555.diff

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

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)

Event Timeline