Skip to content

Commit 2627081

Browse files
Merge branch '2.7' into 2.8
* 2.7: Escape trailing \ in QuestionHelper autocompletion Add "doctrine/annotations" to top-level composer.json nit: Fix phpdoc inconsistency and unreachable statement
2 parents 6ad4fa4 + aa49a00 commit 2627081

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"symfony/yaml": "self.version"
8181
},
8282
"require-dev": {
83+
"doctrine/annotations": "~1.0",
8384
"doctrine/data-fixtures": "1.0.*",
8485
"doctrine/dbal": "~2.4",
8586
"doctrine/orm": "~2.4,>=2.4.5",

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313

1414
use Symfony\Component\Console\Exception\InvalidArgumentException;
1515
use Symfony\Component\Console\Exception\RuntimeException;
16+
use Symfony\Component\Console\Formatter\OutputFormatter;
17+
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
1618
use Symfony\Component\Console\Input\InputInterface;
1719
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1820
use Symfony\Component\Console\Output\OutputInterface;
19-
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
2021
use Symfony\Component\Console\Question\Question;
2122
use Symfony\Component\Console\Question\ChoiceQuestion;
2223

@@ -303,7 +304,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
303304
// Save cursor position
304305
$output->write("\0337");
305306
// Write highlighted text
306-
$output->write('<hl>'.substr($matches[$ofs], $i).'</hl>');
307+
$output->write('<hl>'.OutputFormatter::escapeTrailingBackslash(substr($matches[$ofs], $i)).'</hl>');
307308
// Restore cursor position
308309
$output->write("\0338");
309310
}

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Table
4848
/**
4949
* Number of columns cache.
5050
*
51-
* @var array
51+
* @var int
5252
*/
5353
private $numberOfColumns;
5454

src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,46 @@ public function testAskWithAutocompleteWithNonSequentialKeys()
156156
$this->assertEquals('AsseticBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
157157
}
158158

159+
public function testAutocompleteWithTrailingBackslash()
160+
{
161+
if (!$this->hasSttyAvailable()) {
162+
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
163+
}
164+
165+
$inputStream = $this->getInputStream('E');
166+
167+
$dialog = new QuestionHelper();
168+
$dialog->setInputStream($inputStream);
169+
$helperSet = new HelperSet(array(new FormatterHelper()));
170+
$dialog->setHelperSet($helperSet);
171+
172+
$question = new Question('');
173+
$expectedCompletion = 'ExampleNamespace\\';
174+
$question->setAutocompleterValues(array($expectedCompletion));
175+
176+
$output = $this->createOutputInterface();
177+
$dialog->ask($this->createInputInterfaceMock(), $output, $question);
178+
179+
$outputStream = $output->getStream();
180+
rewind($outputStream);
181+
$actualOutput = stream_get_contents($outputStream);
182+
183+
// Shell control (esc) sequences are not so important: we only care that
184+
// <hl> tag is interpreted correctly and replaced
185+
$irrelevantEscSequences = array(
186+
"\0337" => '', // Save cursor position
187+
"\0338" => '', // Restore cursor position
188+
"\033[K" => '', // Clear line from cursor till the end
189+
);
190+
191+
$importantActualOutput = strtr($actualOutput, $irrelevantEscSequences);
192+
193+
// Remove colors (e.g. "\033[30m", "\033[31;41m")
194+
$importantActualOutput = preg_replace('/\033\[\d+(;\d+)?m/', '', $importantActualOutput);
195+
196+
$this->assertEquals($expectedCompletion, $importantActualOutput);
197+
}
198+
159199
public function testAskHiddenResponse()
160200
{
161201
if ('\\' === DIRECTORY_SEPARATOR) {

src/Symfony/Component/Translation/PluralizationRules.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public static function get($number, $locale)
7171
case 'vi':
7272
case 'zh':
7373
return 0;
74-
break;
7574

7675
case 'af':
7776
case 'bn':

0 commit comments

Comments
 (0)