Skip to content
New issue

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

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

Already on GitHub? # to your account

Invalid characters in stdout �� #52944

Closed
GooseOb opened this issue May 11, 2024 · 6 comments
Closed

Invalid characters in stdout �� #52944

GooseOb opened this issue May 11, 2024 · 6 comments
Labels
help wanted Issues that need assistance from volunteers or PRs that need help to proceed.

Comments

@GooseOb
Copy link

GooseOb commented May 11, 2024

Version

v21.7.3

Platform

WSL2, Manjaro Linux, also tried with git bash

Subsystem

No response

What steps will reproduce the bug?

process.stdout.write large string of utf-8 characters

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

not replacing characters with ��

What do you see instead?

��

Additional information

Cannot reproduce using bun.

Related: GooseOb/taraskevizer#5, fsouza/prettierd#694

@avivkeller
Copy link
Member

Hi! Can you give some example code to reproduce this? My initial assumption is that the encoding is mismatched between UTF-8 and UTF-16 in your terminal.

@GooseOb
Copy link
Author

GooseOb commented May 11, 2024

I tried just to read file and print its content and it works. But if I read from stdin, it makes �� (first is on 698 line). Am I doing something wrong?

latest_be_by.txt

script.mjs

#!/usr/bin/env node

let text = '';
if (!process.isTTY) for await (const chunk of process.stdin) text += chunk;

process.stdout.write(text);
./script.mjs < latest_be_by.txt > be_tarask_by_2.txt

@avivkeller
Copy link
Member

What happens if you replace
process.stdout.write(text);
with
process.stdout.write(text, 'utf-8');?

@GooseOb
Copy link
Author

GooseOb commented May 11, 2024

Nothing changed. I think the problem is with reading from stdin, not with writing.

console.log(//.test(text));
// true

@avivkeller
Copy link
Member

It's possible it's reading in an incorrect encoding, I'm not quite sure, but I'll label this as help wanted so someone else will take a look.

@avivkeller avivkeller added the help wanted Issues that need assistance from volunteers or PRs that need help to proceed. label May 11, 2024
@GooseOb
Copy link
Author

GooseOb commented May 11, 2024

Thank you, I found a right way to read from stdin and it works now

@GooseOb GooseOb closed this as completed May 11, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
help wanted Issues that need assistance from volunteers or PRs that need help to proceed.
Projects
None yet
Development

No branches or pull requests

2 participants