Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Console] don't check tty on stdin, it breaks with "data lost during stream conversion" #36696

Merged
merged 1 commit into from May 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/Symfony/Component/Console/Helper/QuestionHelper.php
Expand Up @@ -462,10 +462,6 @@ private function validateAttempts(callable $interviewer, OutputInterface $output
$error = null;
$attempts = $question->getMaxAttempts();

if (null === $attempts && !$this->isTty()) {
$attempts = 1;
}

while (null === $attempts || $attempts--) {
if (null !== $error) {
$this->writeError($output, $error);
Expand All @@ -477,6 +473,8 @@ private function validateAttempts(callable $interviewer, OutputInterface $output
throw $e;
} catch (\Exception $error) {
}

$attempts = $attempts ?? -(int) $this->isTty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the motivation to move this inside a loop because isTty() result may change between iterations? I wonder how can that happen

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo "$several_answers" | the-command breaks in real life, with stream_isatty() emitting PHP warnings "data lost during stream conversion".

Moving after reading the response means we never hit this line when correct responses are provided. Which is the case in the described situation (programmatic filling of answers.)

}

throw $error;
Expand Down Expand Up @@ -517,7 +515,7 @@ private function isTty(): bool
return stream_isatty($inputStream);
}

if (!\function_exists('posix_isatty')) {
if (\function_exists('posix_isatty')) {
return posix_isatty($inputStream);
}

Expand Down