8000 [Console] fix "data lost during stream conversion" with QuestionHelper · symfony/symfony@0ec319e · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ec319e

Browse files
[Console] fix "data lost during stream conversion" with QuestionHelper
1 parent 2732dda commit 0ec319e

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,6 @@ private function validateAttempts(callable $interviewer, OutputInterface $output
462462
$error = null;
463463
$attempts = $question->getMaxAttempts();
464464

465-
if (null === $attempts && !$this->isTty()) {
466-
$attempts = 1;
467-
}
468-
469465
while (null === $attempts || $attempts--) {
470466
if (null !== $error) {
471467
$this->writeError($output, $error);
@@ -477,6 +473,8 @@ private function validateAttempts(callable $interviewer, OutputInterface $output
477473
throw $e;
478474
} catch (\Exception $error) {
479475
}
476+
477+
$attempts = $attempts ?? -(int) $this->isTty();
480478
}
481479

482480
throw $error;
@@ -517,7 +515,7 @@ private function isTty(): bool
517515
return stream_isatty($inputStream);
518516
}
519517

520-
if (!\function_exists('posix_isatty')) {
518+
if (\function_exists('posix_isatty')) {
521519
return posix_isatty($inputStream);
522520
}
523521

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public function testAskConfirmation($question, $expected, $default = true)
446446
{
447447
$dialog = new QuestionHelper();
448448

449-
$inputStream = $this->getInputStream($question."\n");
449+
$inputStream = $this->getInputStream($question."\n".$question."\n");
450450
$question = new ConfirmationQuestion('Do you like French fries?', $default);
451451
$this->assertEquals($expected, $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question), 'confirmation question should '.($expected ? 'pass' : 'cancel'));
452452
}

0 commit comments

Comments
 (0)
0