Changeset View
Changeset View
Standalone View
Standalone View
src/xsprintf/csprintf.php
| Show All 9 Lines | |||||
| * | * | ||||
| * %P | * %P | ||||
| * Password (or other sensitive parameter) to escape. Pass a | * Password (or other sensitive parameter) to escape. Pass a | ||||
| * PhutilOpaqueEnvelope. | * PhutilOpaqueEnvelope. | ||||
| * | * | ||||
| * %C (Raw Command) | * %C (Raw Command) | ||||
| * Passes the argument through without escaping. Dangerous! | * Passes the argument through without escaping. Dangerous! | ||||
| * | * | ||||
| * %R | |||||
| * A more "readable" version of "%s". This will try to print the command | |||||
| * without any escaping if it contains only characters which are safe | |||||
| * in any context. The intent is to produce prettier human-readable | |||||
| * commands. | |||||
| * | |||||
| * Generally, you should invoke shell commands via execx() rather than by | * Generally, you should invoke shell commands via execx() rather than by | ||||
| * calling csprintf() directly. | * calling csprintf() directly. | ||||
| * | * | ||||
| * @param string sprintf()-style format string. | * @param string sprintf()-style format string. | ||||
| * @param ... Zero or more arguments. | * @param ... Zero or more arguments. | ||||
| * @return string Formatted string, escaped appropriately for shell contexts. | * @return string Formatted string, escaped appropriately for shell contexts. | ||||
| * @group exec | * @group exec | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | case 'L': | ||||
| // Check that the value is a non-empty array. | // Check that the value is a non-empty array. | ||||
| if (!is_array($value)) { | if (!is_array($value)) { | ||||
| throw new Exception("Expected an array for %Ls conversion."); | throw new Exception("Expected an array for %Ls conversion."); | ||||
| } | } | ||||
| // Convert the list of strings to a single string. | // Convert the list of strings to a single string. | ||||
| $value = implode(' ', array_map('escapeshellarg', $value)); | $value = implode(' ', array_map('escapeshellarg', $value)); | ||||
| break; | break; | ||||
| case 'R': | |||||
| if (!preg_match('(^[a-zA-Z0-9:/@._-]+$)', $value)) { | |||||
| $value = escapeshellarg($value); | |||||
| } | |||||
| $type = 's'; | |||||
| break; | |||||
| case 's': | case 's': | ||||
| $value = escapeshellarg($value); | $value = escapeshellarg($value); | ||||
| $type = 's'; | $type = 's'; | ||||
| break; | break; | ||||
| case 'P': | case 'P': | ||||
| if (!($value instanceof PhutilOpaqueEnvelope)) { | if (!($value instanceof PhutilOpaqueEnvelope)) { | ||||
| throw new Exception( | throw new Exception( | ||||
| "Expected PhutilOpaqueEnvelope for %P conversion."); | "Expected PhutilOpaqueEnvelope for %P conversion."); | ||||
| Show All 16 Lines | |||||