8000 [Console] Fix infinite loop on missing input by chalasr · Pull Request #20377 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Fix infinite loop on missing input #20377

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

Merged

Conversation

chalasr
Copy link
Member
@chalasr chalasr commented Nov 1, 2016
Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #20277
License MIT
Doc PR n/a

This fixes the infinite loop occurring when no input is provided for a question which has a validator and no max attempts (null), e.g. when using SymfonyStyle::ask() which automatically adds a validator.

public function testAskThrowsExceptionOnMissingInputWithValidator()
{
$dialog = new QuestionHelper();
$dialog->setInputStream($this->getInputStream(''));
Copy link
Member Author
@chalasr chalasr Nov 1, 2016

Choose a reason for hiding this comment

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

Be careful when merging, this method has been deprecated so we need to remove this line and change $this->createInputInterfaceMock() by $this->createStreamableInputInterfaceMock($this->getInputStream('')) below. Same for the test added in SymfonyQuestionHelperTest.

@chalasr chalasr mentioned this pull request Nov 1, 2016
@nicolas-grekas
Copy link
Member

Could be combined with #20376, would ease review, and code is related.

@chalasr chalasr force-pushed the console/fix_infinite_loop_on_missing_input branch from 9405bd5 to cb0a58b Compare November 2, 2016 09:11
@chalasr
Copy link
Member Author
chalasr commented Nov 2, 2016

@nicolas-grekas Indeed, done.

@fabpot
Copy link
Member
fabpot commented Nov 2, 2016

👍

@@ -136,7 +136,7 @@ public function doAsk(OutputInterface $output, Question $question)
if (false === $ret) {
$ret = fgets($inputStream, 4096);
if (false === $ret) {
throw new \RuntimeException('Aborted');
throw new RuntimeException('Aborted');
Copy link
Member

Choose a reason for hiding this comment

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

I know that this exception class does not exist in 2.7, but the bug is there as well, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it is. Would you catch any \RuntimeException in 2.7?

Copy link
Member

Choose a reason for hiding this comment

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

I think it would make sense

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't it doable to backport this exception class in 2.7?

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, I think that would be best.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure it is the right way to proceed but I added a simple extension of \RuntimeException which is used where it's needed, and rebased this.

@chalasr chalasr force-pushed the console/fix_infinite_loop_on_missing_input branch from cb0a58b to 9a8943e Compare November 2, 2016 23:48
@chalasr chalasr changed the base branch from 2.8 to 2.7 November 2, 2016 23:48
@chalasr chalasr force-pushed the console/fix_infinite_loop_on_missing_input branch from 9a8943e to 263fad5 Compare November 2, 2016 23:50
@chalasr chalasr changed the base branch from 2.7 to 2.8 November 2, 2016 23:51
@chalasr chalasr force-pushed the console/fix_infinite_loop_on_missing_input branch from 263fad5 to 04ccc84 Compare November 2, 2016 23:52
[Console] Use console exception for missing input

Backport Console RuntimeException in 2.7
@chalasr chalasr changed the base branch from 2.8 to 2.7 November 3, 2016 08:52
@chalasr chalasr force-pushed the console/fix_infinite_loop_on_missing_input branch from 04ccc84 to e64de1e Compare November 3, 2016 08:52
@fabpot
Copy link
Member
fabpot commented Nov 4, 2016

Thank you @chalasr.

@fabpot fabpot merged commit e64de1e into symfony:2.7 Nov 4, 2016
fabpot added a commit that referenced this pull request Nov 4, 2016
This PR was merged into the 2.7 branch.

Discussion
----------

[Console] Fix infinite loop on missing input

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20277
| License       | MIT
| Doc PR        | n/a

This fixes the infinite loop occurring when no input is provided for a question which has a validator and no max attempts (`null`), e.g. when using `SymfonyStyle::ask()` which automatically adds a validator.

Commits
-------

e64de1e [Console] Fix infinite loop on missing input
@chalasr chalasr deleted the console/fix_infinite_loop_on_missing_input branch November 4, 2016 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0