Changeset View
Changeset View
Standalone View
Standalone View
src/xsprintf/PhutilCommandString.php
Context not available. | |||||
} | } | ||||
private static function escapeLinux($value) { | private static function escapeLinux($value) { | ||||
if (strpos($value, "\0") !== false) { | if (@strpos($value, "\0") !== false) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Command string argument includes a NULL byte. This byte can not '. | 'Command string argument includes a NULL byte. This byte can not '. | ||||
Context not available. | |||||
// characters, we do not need to escape it. This makes debugging | // characters, we do not need to escape it. This makes debugging | ||||
// workflows a little more user-friendly by making command output | // workflows a little more user-friendly by making command output | ||||
// more readable. | // more readable. | ||||
if (preg_match('(^[a-zA-Z0-9:/@._+-]+\z)', $value)) { | if (@preg_match('(^[a-zA-Z0-9:/@._+-]+\z)', $value)) { | ||||
return $value; | return $value; | ||||
} | } | ||||
return escapeshellarg($value); | return @escapeshellarg($value); | ||||
} | } | ||||
private static function escapeWindows($value) { | private static function escapeWindows($value) { | ||||
if (strpos($value, "\0") !== false) { | if (@strpos($value, "\0") !== false) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Command string argument includes a NULL byte. This byte can not '. | 'Command string argument includes a NULL byte. This byte can not '. | ||||
Context not available. | |||||
'line arguments in Windows environments.')); | 'line arguments in Windows environments.')); | ||||
} | } | ||||
$has_backslash = (strpos($value, '\\') !== false); | $has_backslash = (@strpos($value, '\\') !== false); | ||||
$has_space = (strpos($value, ' ') !== false); | $has_space = (@strpos($value, ' ') !== false); | ||||
$has_quote = (strpos($value, '"') !== false); | $has_quote = (@strpos($value, '"') !== false); | ||||
$is_empty = (strlen($value) === 0); | $is_empty = (@strlen($value) === 0); | ||||
// If a backslash appears before another backslash, a double quote, or | // If a backslash appears before another backslash, a double quote, or | ||||
// the end of the argument, we must escape it. Otherwise, we must leave | // the end of the argument, we must escape it. Otherwise, we must leave | ||||
Context not available. |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0