Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e2d4904

Browse filesBrowse files
committed
Render all line breaks according to the exception message
1 parent 800f306 commit e2d4904
Copy full SHA for e2d4904

File tree

3 files changed

+30
-4
lines changed
Filter options

3 files changed

+30
-4
lines changed

‎src/Symfony/Component/Console/Application.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Application.php
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ public function renderException($e, $output)
681681
$width = 1 << 31;
682682
}
683683
$lines = array();
684-
foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) {
684+
foreach (preg_split('/\r?\n/', trim($e->getMessage())) as $line) {
685685
foreach ($this->splitStringByWidth($line, $width - 4) as $line) {
686686
// pre-format lines to get the right string length
687687
$lineLength = Helper::strlen($line) + 4;
@@ -1133,9 +1133,8 @@ private function splitStringByWidth($string, $width)
11331133
$lines[] = str_pad($line, $width);
11341134
$line = $char;
11351135
}
1136-
if ('' !== $line) {
1137-
$lines[] = count($lines) ? str_pad($line, $width) : $line;
1138-
}
1136+
1137+
$lines[] = count($lines) ? str_pad($line, $width) : $line;
11391138

11401139
mb_convert_variables($encoding, 'utf8', $lines);
11411140

‎src/Symfony/Component/Console/Tests/ApplicationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/ApplicationTest.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,22 @@ public function testRenderExceptionEscapesLines()
608608
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_escapeslines.txt', $tester->getDisplay(true), '->renderException() escapes lines containing formatting');
609609
}
610610

611+
public function testRenderExceptionLineBreaks()
612+
{
613+
$application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(array('getTerminalWidth'))->getMock();
614+
$application->setAutoExit(false);
615+
$application->expects($this->any())
616+
->method('getTerminalWidth')
617+
->will($this->returnValue(120));
618+
$application->register('foo')->setCode(function () {
619+
throw new \InvalidArgumentException("\n\nline 1 with extra spaces \nline 2\n\nline 4\n");
620+
});
621+
$tester = new ApplicationTester($application);
622+
623+
$tester->run(array('command' => 'foo'), array('decorated' => false));
624+
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_linebreaks.txt', $tester->getDisplay(true), '->renderException() keep multiple line breaks');
625+
}
626+
611627
public function testRun()
612628
{
613629
$application = new Application();
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
3+
[InvalidArgumentException]
4+
line 1 with extra spaces
5+
line 2
6+
7+
line 4
8+
9+
10+
foo
11+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.