10000 [Console] clone stream on multiline questions so EOT doesn't close input by ramsey · Pull Request #38351 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] clone stream on multiline questions so EOT doesn't close input #38351

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
merged 1 commit into from
Sep 30, 2020
Merged

[Console] clone stream on multiline questions so EOT doesn't close input #38351

merged 1 commit into from
Sep 30, 2020

Conversation

ramsey
Copy link
Contributor
@ramsey ramsey commented Sep 29, 2020
Q A
Branch? master
Bug fix? yes
New feature? no
Deprecations? no
Tickets N/A
License MIT
Doc PR N/A

This fixes a bug in the multiline question feature that was introduced in #37683.

Today, @epitre commented on #37683 (comment):

If I ask a question AFTER using the multiline option in a previous question, then it seems that the ctrl+d is kind of saved, and the command gets aborted.

I'm honestly not sure how I missed this while working on #37683, since I was testing it with multiple questions, but I think it might have resulted from some of the back-and-forth and the lack of ability to effectively test the EOT character from a unit test.

The solution was to clone the input stream resource and use the clone to read the multiline input and capture the EOT byte. In this way, the primary input stream is not closed by the EOT.

This is similar to @epitre's solution in #38345, but I'm using the uri and mode from stream_get_meta_data() to create the new stream, and if the existing stream has any data and is seekable and writable (like the streams used in the tests), I add the data to the clone and seek to the same offset.

I've ensured that this solution works on a question that is in the middle of a series of other questions, and I've tested in on *nix and Windows. I've also improved the tests for multiline questions. While I'm unable to test (with a unit test) that an EOT character effectively stops reading from STDIN while continuing to the next question and prompt, I feel confident that the tests here provide sufficient coverage.

@chalasr chalasr added this to the next milestone Sep 30, 2020
@chalasr
Copy link
Member
chalasr commented Sep 30, 2020

Thank you @ramsey.

@chalasr chalasr closed this in e8dd14a Sep 30, 2020
@chalasr chalasr merged commit e8dd14a into symfony:master Sep 30, 2020
@ramsey ramsey deleted the bug/multiline-question branch September 30, 2020 19:55
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.2 Oct 5, 2020
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.

5 participants
0