Changeset View
Changeset View
Standalone View
Standalone View
src/xsprintf/__tests__/PhutilCsprintfTestCase.php
| Show All 23 Lines | final class PhutilCsprintfTestCase extends PhutilTestCase { | ||||
| public function testNoPowershell() { | public function testNoPowershell() { | ||||
| if (!phutil_is_windows()) { | if (!phutil_is_windows()) { | ||||
| $cmd = csprintf('%s', '#'); | $cmd = csprintf('%s', '#'); | ||||
| $cmd->setEscapingMode(PhutilCommandString::MODE_DEFAULT); | $cmd->setEscapingMode(PhutilCommandString::MODE_DEFAULT); | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| '\'#\'', | '\'#\'', | ||||
| (string)$cmd); | (string)$cmd); | ||||
| } else { | |||||
| $this->assertSkipped(pht("This test doesn't work on Windows.")); | |||||
BYK: Well, this is not really accurate. I should probably branch and use the expected Windows… | |||||
| } | } | ||||
| } | } | ||||
| 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->assertTrue(strpos($command, 'hunter2trustno1') !== false); | $this->assertTrue(strpos($command, 'hunter2trustno1') !== false); | ||||
| Show All 31 Lines | list($out) = execx( | ||||
| csprintf( | csprintf( | ||||
| 'sh -c %s', | 'sh -c %s', | ||||
| csprintf( | csprintf( | ||||
| 'echo %P', | 'echo %P', | ||||
| new PhutilOpaqueEnvelope('!@#$%^&*()'))))); | new PhutilOpaqueEnvelope('!@#$%^&*()'))))); | ||||
| $this->assertTrue(strpos($out, '!@#$%^&*()') !== false); | $this->assertTrue(strpos($out, '!@#$%^&*()') !== false); | ||||
| } | } | ||||
| public function testEdgeCases() { | |||||
Not Done Inline ActionsThese test cases do not test what they intend to test. In PHP, '\0' is the string literal "backslash, zero", not a null byte. Likewise, '\n' and '\r' are not newline characters. When these strings are changed to use double quotes, the test cases fail. epriestley: These test cases do not test what they intend to test.
In PHP, `'\0'` is the string literal… | |||||
Not Done Inline ActionsAh, okay I see. Will fix. BYK: Ah, okay I see. Will fix. | |||||
Not Done Inline ActionsTurns out it is not possible to pass a NULL BYTE through the command line anyways so gonna drop that case. Working on the new lines which are the other two problems. BYK: Turns out it is not possible to pass a NULL BYTE through the command line anyways so gonna drop… | |||||
| $edgeCases = array( | |||||
| '\0', // null byte | |||||
| '\\', | |||||
| '%', | |||||
| '%%', | |||||
| ' ', // space | |||||
| '', // empty string | |||||
| '-', | |||||
| '/flag', | |||||
| '\\\^\%\\\'\ \\', | |||||
| '%PATH%', | |||||
| '%XYZ%', | |||||
| '%%HOMEDIR%', | |||||
| '\n', // newline | |||||
| '\r', // newline | |||||
| 'a b', | |||||
| '"a b"', | |||||
| '"%%$HOMEDIR%^^"', | |||||
| '\'a b\'', | |||||
| '^%HO ^"M\'EDIR^%^%\'', | |||||
| '"\'a\0\r\nb%PATH%%`\'"\'`\'`\'', | |||||
| ); | |||||
| foreach ($edgeCases as $edgeCase) { | |||||
| list($output) = execx('php -r "echo $argv[1];" -- %s', $edgeCase); | |||||
BYKAuthorUnsubmitted Not Done Inline ActionsShould probably do list($output) = execx('php -r %s -- %s', 'echo $argv[1];', $edgeCase);instead. BYK: Should probably do
list($output) = execx('php -r %s -- %s', 'echo $argv[1];', $edgeCase)… | |||||
| $this->assertEqual($edgeCase, $output); | |||||
| } | |||||
| } | |||||
| } | } | ||||
Well, this is not really accurate. I should probably branch and use the expected Windows version at this point. What do you think?