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

fs: writing utf8 to fd 1 results in garbled output on windows #24550

Closed
mcollina opened this issue Nov 21, 2018 · 9 comments
Closed

fs: writing utf8 to fd 1 results in garbled output on windows #24550

mcollina opened this issue Nov 21, 2018 · 9 comments
Labels
fs Issues and PRs related to the fs subsystem / file system. known limitation Issues that are identified as known limitations. libuv Issues and PRs related to the libuv dependency or the uv binding. tty Issues and PRs related to the tty subsystem. windows Issues and PRs related to the Windows platform.

Comments

@mcollina
Copy link
Member

  • Version: 10.13 (also 8.x and before)
  • Platform: Windows
  • Subsystem: fs

The following snipped works fine on Linux and Mac OS X, but not on Windows:

const fs = require('fs')
const str = 'èè'
fs.write(1, str + '\n', 0, '', console.log)

Note that using process.stdout.write is actually working as expected.

@mcollina
Copy link
Member Author

This might be related to libuv @nodejs/libuv @nodejs/platform-windows.

@bzoz
Copy link
Contributor

bzoz commented Nov 21, 2018

Windows console does not speak UTF-8 (yet.. and some more details). Libuv converts UTF-8 to UCS-2 before writing to TTY:

if (!MultiByteToWideChar(CP_UTF8,

@refack
Copy link
Contributor

refack commented Nov 21, 2018

To elaborate on @bzoz

> s = new tty.WriteStream(1)
> s.write('èè\n');
èè
true

and in Windows Insider build 18282:

> const fs = require('fs')
undefined
> const str = 'èè'
undefined
> fs.write(1, str + '\n', 0, '', console.log)
èè
undefined
> null 5 èè

@refack refack added the known limitation Issues that are identified as known limitations. label Nov 21, 2018
@mcollina
Copy link
Member Author

Note that writing:

const fs = require('fs')
const str = 'èè'
fs.write(1, str + '\n', null, 'ucs2', console.log)

does not work either.

@seishun
Copy link
Contributor

seishun commented Nov 21, 2018

Is there anything Node can or should do about it? Silently converting text seems like a bad idea.

@refack
Copy link
Contributor

refack commented Nov 21, 2018

Is there anything Node can or should do about it? Silently converting text seems like a bad idea.

IMO - Document as known limitation.

@refack
Copy link
Contributor

refack commented Nov 21, 2018

P.S. @mcollina does the info in https://ss64.com/nt/chcp.html help (run chcp 65001 and use a Unicode enabled font)?

@refack refack added windows Issues and PRs related to the Windows platform. fs Issues and PRs related to the fs subsystem / file system. console Issues and PRs related to the console subsystem. tty Issues and PRs related to the tty subsystem. labels Nov 21, 2018
@mcollina
Copy link
Member Author

chcp 65001 works super-smoothly. IMHO we should just document that.

const fs = require('fs')
const str = 'èè'
fs.write(1, str + '\n', null, 'utf8', console.log)

@addaleax addaleax added libuv Issues and PRs related to the libuv dependency or the uv binding. and removed console Issues and PRs related to the console subsystem. labels Nov 21, 2018
mcollina added a commit to mcollina/node that referenced this issue Nov 22, 2018
Trott pushed a commit to Trott/io.js that referenced this issue Nov 28, 2018
Fixes: nodejs#24550

PR-URL: nodejs#24571
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
@Trott
Copy link
Member

Trott commented Nov 28, 2018

Fixed in 086482d

@Trott Trott closed this as completed Nov 28, 2018
targos pushed a commit that referenced this issue Nov 28, 2018
Fixes: #24550

PR-URL: #24571
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
refack pushed a commit to refack/node that referenced this issue Jan 14, 2019
Fixes: nodejs#24550

PR-URL: nodejs#24571
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
BethGriggs pushed a commit that referenced this issue Feb 12, 2019
Fixes: #24550

PR-URL: #24571
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
BethGriggs pushed a commit that referenced this issue Feb 20, 2019
Fixes: #24550

PR-URL: #24571
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
rvagg pushed a commit that referenced this issue Feb 28, 2019
Fixes: #24550

PR-URL: #24571
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. known limitation Issues that are identified as known limitations. libuv Issues and PRs related to the libuv dependency or the uv binding. tty Issues and PRs related to the tty subsystem. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

6 participants