[Console] fixed output escaping when using the process helper
This commit is contained in:
parent
b3b41d5d8d
commit
bf7a90eb87
@ -48,7 +48,7 @@ class ProcessHelper extends Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($verbosity <= $output->getVerbosity()) {
|
if ($verbosity <= $output->getVerbosity()) {
|
||||||
$output->write($formatter->start(spl_object_hash($process), $process->getCommandLine()));
|
$output->write($formatter->start(spl_object_hash($process), $this->escapeString($process->getCommandLine())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($output->isDebug()) {
|
if ($output->isDebug()) {
|
||||||
@ -63,7 +63,7 @@ class ProcessHelper extends Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$process->isSuccessful() && null !== $error) {
|
if (!$process->isSuccessful() && null !== $error) {
|
||||||
$output->writeln(sprintf('<error>%s</error>', $error));
|
$output->writeln(sprintf('<error>%s</error>', $this->escapeString($error)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $process;
|
return $process;
|
||||||
@ -111,8 +111,9 @@ class ProcessHelper extends Helper
|
|||||||
{
|
{
|
||||||
$formatter = $this->getHelperSet()->get('debug_formatter');
|
$formatter = $this->getHelperSet()->get('debug_formatter');
|
||||||
|
|
||||||
return function ($type, $buffer) use ($output, $process, $callback, $formatter) {
|
$that = $this;
|
||||||
$output->write($formatter->progress(spl_object_hash($process), $buffer, Process::ERR === $type));
|
return function ($type, $buffer) use ($output, $process, $callback, $formatter, $that) {
|
||||||
|
$output->write($formatter->progress(spl_object_hash($process), $that->escapeString($buffer), Process::ERR === $type));
|
||||||
|
|
||||||
if (null !== $callback) {
|
if (null !== $callback) {
|
||||||
call_user_func($callback, $type, $buffer);
|
call_user_func($callback, $type, $buffer);
|
||||||
@ -120,6 +121,16 @@ class ProcessHelper extends Helper
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is public for PHP 5.3 compatibility, it should be private.
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
public function escapeString($str)
|
||||||
|
{
|
||||||
|
return str_replace('<', '\\<', $str);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -57,6 +57,12 @@ EOT;
|
|||||||
OUT 42
|
OUT 42
|
||||||
RES Command ran successfully
|
RES Command ran successfully
|
||||||
|
|
||||||
|
EOT;
|
||||||
|
$successOutputDebugWithTags = <<<EOT
|
||||||
|
RUN php -r "echo \"<info>42</info>\";"
|
||||||
|
OUT <info>42</info>
|
||||||
|
RES Command ran successfully
|
||||||
|
|
||||||
EOT;
|
EOT;
|
||||||
$successOutputProcessDebug = <<<EOT
|
$successOutputProcessDebug = <<<EOT
|
||||||
RUN 'php' '-r' 'echo 42;'
|
RUN 'php' '-r' 'echo 42;'
|
||||||
@ -86,6 +92,7 @@ EOT;
|
|||||||
array('', 'php -r "echo 42;"', StreamOutput::VERBOSITY_VERBOSE, null),
|
array('', 'php -r "echo 42;"', StreamOutput::VERBOSITY_VERBOSE, null),
|
||||||
array($successOutputVerbose, 'php -r "echo 42;"', StreamOutput::VERBOSITY_VERY_VERBOSE, null),
|
array($successOutputVerbose, 'php -r "echo 42;"', StreamOutput::VERBOSITY_VERY_VERBOSE, null),
|
||||||
array($successOutputDebug, 'php -r "echo 42;"', StreamOutput::VERBOSITY_DEBUG, null),
|
array($successOutputDebug, 'php -r "echo 42;"', StreamOutput::VERBOSITY_DEBUG, null),
|
||||||
|
array($successOutputDebugWithTags, 'php -r "echo \"<info>42</info>\";"', StreamOutput::VERBOSITY_DEBUG, null),
|
||||||
array('', 'php -r "syntax error"', StreamOutput::VERBOSITY_VERBOSE, null),
|
array('', 'php -r "syntax error"', StreamOutput::VERBOSITY_VERBOSE, null),
|
||||||
array($syntaxErrorOutputVerbose, 'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_VERY_VERBOSE, null),
|
array($syntaxErrorOutputVerbose, 'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_VERY_VERBOSE, null),
|
||||||
array($syntaxErrorOutputDebug, 'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_DEBUG, null),
|
array($syntaxErrorOutputDebug, 'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_DEBUG, null),
|
||||||
|
Reference in New Issue
Block a user