iiegor / ptyw.js

Bindings to forkpty(3) for node.js.
MIT License
20 stars 13 forks source link

Non UTF-8 Data Corruption #6

Open NuSkooler opened 8 years ago

NuSkooler commented 8 years ago

Overview Non UTF-8 data is corrupted by the time it gets to the data listener.

Example Use ptyw.js to spawn DOSEMU or QEMU + FreeDOS under CentOS 7 using their virtual serial ports. From there, launch something that outputs ANSI graphics (I am duplicating this launching DOS BBS doors such as L.O.R.D.). This will produce CP437 data being sent to the serial port -> stdio -> ptyw.js. It cannot be decoded as such, however.

If you launch the same applications directly from the terminal using cp437 decoding (e.g. using https://github.com/keaston/cp437) the data is decoded properly.

EDIT: Updated from data learned in second comment.

NuSkooler commented 8 years ago

Sorry for all the updates, but I think I found the problem. Nothing to do with termios, but the setEncoding on the stream @ https://github.com/iiegor/ptyw.js/blob/master/lib/pty.js#L125 (and others)

This assumes data is UTF-8, which is certainly not always the case. Omitting it, and letting the consumer's data listener take care of encodings works. I had made this modificaiton on my ElementaryOS and Windows boxes but had a clean checkout on CentOS 7.