Changeset View
Changeset View
Standalone View
Standalone View
src/xsprintf/__tests__/PhutilcsprintfTestCase.php
| <?php | <?php | ||||
| final class PhutilcsprintfTestCase extends ArcanistTestCase { | final class PhutilcsprintfTestCase extends ArcanistTestCase { | ||||
| public function testCommandReadableEscapes() { | |||||
| // For arguments comprised of only characters which are safe in any context, | |||||
| // %R this should avoid adding quotes. | |||||
| $this->assertEqual( | |||||
| true, | |||||
| ('ab' === (string)csprintf('%R', 'ab'))); | |||||
| // For arguments which have any characters which are not safe in some | |||||
| // context, %R should apply standard escaping. | |||||
| $this->assertEqual( | |||||
| false, | |||||
| ('a b' === (string)csprintf('%R', 'a b'))); | |||||
| } | |||||
| public function testPasswords() { | public function testPasswords() { | ||||
| // Normal "%s" doesn't do anything special. | // Normal "%s" doesn't do anything special. | ||||
| $command = csprintf('echo %s', 'hunter2trustno1'); | $command = csprintf('echo %s', 'hunter2trustno1'); | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| true, | true, | ||||
| strpos($command, 'hunter2trustno1') !== false); | strpos($command, 'hunter2trustno1') !== false); | ||||
| // "%P" takes a PhutilOpaqueEnvelope. | // "%P" takes a PhutilOpaqueEnvelope. | ||||
| $caught = null; | $caught = null; | ||||
| try { | try { | ||||
| csprintf('echo %P', 'hunter2trustno1'); | csprintf('echo %P', 'hunter2trustno1'); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| $caught = $ex; | $caught = $ex; | ||||
| } | } | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| Show All 38 Lines | |||||