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

fix(cli): read stdin as utf-8 on windows #18699

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

njhanley
Copy link
Contributor

@njhanley njhanley commented Apr 14, 2023

Switching to std::io::stdin() has the drawback of an internal buffer that cannot be disabled. #14704 introduced a test for non-buffered stdin, though I can't see why this is important or expected behavior.

Alternatively we could borrow the internal StdinRaw implementation from the Rust standard library.

Initially I included an integration test however I later removed it. On Windows, the testing framework allocates a pseudoterminal which always returns UTF-8-encoded text, causing the test to falsely pass. I'm unsure how else to test for this bug.

Fixes #18240.

Reading directly from console input on Windows returns text encoded
in the current code page. Instead use `std::io::stdin()`.
`std::io::stdin()` is unconditionally buffered.
The intent was to test for non-UTF-8-encoded console input on Windows
but the testing framework allocates a pseudoterminal for integration
tests, which always returns UTF-8-encoded text, unlike a real console.
@bartlomieju bartlomieju requested a review from dsherret April 14, 2023 10:55
@njhanley njhanley marked this pull request as ready for review April 27, 2023 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stdin.read (and stdin.readSync) corrupt non-ASCII input on Windows
3 participants