parent
0bcda60dab
commit
5b1e9be316
|
@ -30,7 +30,7 @@ class IcingaCommandFileCommandRenderer implements IcingaCommandRendererInterface
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function escape($commandString)
|
||||
protected function escape($commandString)
|
||||
{
|
||||
return str_replace(array("\r", "\n"), array('\r', '\n'), $commandString);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class IcingaCommandFileCommandRenderer implements IcingaCommandRendererInterface
|
|||
if ($now === null) {
|
||||
$now = time();
|
||||
}
|
||||
return sprintf('[%u] %s', $now, $this->$renderMethod($command));
|
||||
return sprintf('[%u] %s', $now, $this->escape($this->$renderMethod($command)));
|
||||
}
|
||||
|
||||
public function renderAddComment(AddCommentCommand $command)
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Regression;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Module\Monitoring\Command\IcingaCommand;
|
||||
use Icinga\Module\Monitoring\Command\Renderer\IcingaCommandFileCommandRenderer;
|
||||
|
||||
|
||||
/**
|
||||
* A command that has a hardcoded parameter with newlines
|
||||
*/
|
||||
class Bug6088Command extends IcingaCommand
|
||||
{
|
||||
public function getParameterWithCarriageReturnAndLineFeed()
|
||||
{
|
||||
return "foo\r\nbar";
|
||||
}
|
||||
|
||||
public function getBug()
|
||||
{
|
||||
return '6088';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A subclass of IcingaCommandFileCommandRenderer to utiliseIcingaCommandFileCommandRenderer
|
||||
* to render an instance of Bug6088Command
|
||||
*/
|
||||
class Bug6088CommandFileCommandRenderer extends IcingaCommandFileCommandRenderer
|
||||
{
|
||||
public function renderBug6088(Bug6088Command $command)
|
||||
{
|
||||
return 'SOLVE_BUG;' . $command->getBug() . ';' . $command->getParameterWithCarriageReturnAndLineFeed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class Bug6088
|
||||
*
|
||||
* Multi-line comments don't work
|
||||
*
|
||||
* @see https://dev.icinga.org/issues/6088
|
||||
*/
|
||||
class Bug6088Test extends BaseTestCase
|
||||
{
|
||||
public function testWhetherCommandParametersWithMultipleLinesAreProperlyEscaped()
|
||||
{
|
||||
$command = new Bug6088Command();
|
||||
$renderer = new Bug6088CommandFileCommandRenderer();
|
||||
$commandString = $renderer->render($command);
|
||||
|
||||
$this->assertEquals(
|
||||
'SOLVE_BUG;6088;foo\r\nbar',
|
||||
substr($commandString, strpos($commandString, ' ') + 1),
|
||||
'Command parameters with multiple lines are not properly escaped'
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue